基本配置
http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;upstream backend {server localhost:7001 weight=1;server localhost:7002 weight=1;}server {listen 8888;server_name localhost;location / {proxy_pass http://backend;}
失败重试
http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;upstream backend {server localhost:7001 max_fails=2 fail_timeout=10s weight=1;server localhost:7002 max_fails=2 fail_timeout=10s weight=1;}server {listen 8888;server_name localhost;location / {proxy_connect_timeout 5s;proxy_read_timeout 5s;proxy_send_timeout 5s;proxy_next_upstream error timeout;proxy_next_upstream_timeout 10s;proxy_next_upstream_tries 2;proxy_pass http://backend;add_header upstream_addr $upstream_addr;}
tcp心跳
upstream backend {server localhost:7001 weight=1;server localhost:7002 weight=1;check interval=3000 rise=1 fall=3 timeout=2000 type=tcp;}
http心跳
upstream backend {server localhost:7001 weight=1;server localhost:7002 weight=1;check interval=3000 rise=1 fall=3 timeout=2000 type=http;check_http_send "HEAD /status HTTP/1.0\r\n\r\n"check_http_expect_alive http_2xx http_3xx;}
域名上游服务器(略)
备份上游服务器
upstream backend {server localhost:7001 weight=1;server localhost:7002 weight=1 backup;}
不可用上游服务器
upstream backend {server localhost:7001 weight=1;server localhost:7002 weight=1 down;}
长连接
upstream backend {server localhost:7001 weight=1;server localhost:7002 weight=1 backup;keepalive 100;}server {listen 8888;server_name localhost;location / {# 支持keep_alive # 如果是http/1.0 需要配置发送 Connection "Keep-Alive" 请求头proxy_http_version 1.1;proxy_set_header Connection "";proxy_pass http://backend;}