upstream lbs {
server ip;
server ip;
}
server {
listen 80;
server_name 域名;
location / {
proxy_pass http://lbs;
}
}
分配策略
轮询 (默认)
权重
weight 默认1;
值越大,分配越多
upstream lbs {
server ip weight=1;
server ip weight=2;
}
哈希
ip_hash
每个访客访问固定服务器,可解决session问题
upstream lbs {
ip_hash
server ip;
server ip;
}
fair
按照后端响应时间分配
upstream lbs {
server ip;
server ip;
fair
}
登录
upstream lbs {
sticky;
server ip;
server ip;
}
server {
listen 80;
server_name 域名;
location / {
proxy_pass http://lbs;
client_max_body_size 1000m;
proxy_set_header terminal_id $http_terminal_id;
proxy_set_header Host $host:$server_port;
proxy_set_header X_Read_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forearded_for;
proxy_set_header X-Forwarded-Proto "https";
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
# keepalive_timeout 300;
# proxy_connect_timeout 300;
# proxy_read_timeout 300;
}
}
应用
upstream lbs {
server ip;
server ip;
}
server {
listen 80;
server_name 域名;
location / {
proxy_pass http://lbs;
client_max_body_size 1000m;
proxy_set_header terminal_id $http_terminal_id;
proxy_set_header Host $host:$server_port;
proxy_set_header X_Read_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
index index.html index.htm index.jsp;
# add_header Access-Control-Allow-Origin *;
# proxy_set_header X-Forwarded-Proto "https";
}
}