upstream backserver{
//-------------负载均衡算法--------------
//轮询-默认
//ip_hash;
//least_conn;
//least_time;
//random;
//----需额外的模块支持---
//consistent_hash;
//fair;
//----------------------
//----------------------------------------
ip_hash;
server test1.server:8080 weight=5;
server test2.server:8080;
server test2.server:8080 backup;
}
server {
listen 8080;
server_name front.server.com;
client_max_body_size 200m;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $remote_addr;
location ^~ /server_context {
client_max_body_size 200m;
proxy_pass http://backserver/server_context/;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
root /home/dist/;
client_max_body_size 200m;
index index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.html?s=$1 last;
break;
}
}
}