#Nginx负载均衡常用模式 https://my.oschina.net/u/3385288/blog/4635842 worker_processes 1;#==工作进程数,一般设置为cpu核心数 events { worker_connections 1024; #==最大连接数,一般设置为cpu*2048 } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; #==客户端链接超时时间 upstream MyServer { server 127.0.0.1:9001; server 127.0.0.1:9002; server 127.0.0.1:9003; } upstream host1 { server 127.0.0.1:9001; } upstream host2 { server 127.0.0.1:9002; } upstream default { server 127.0.0.1:9003; } map $COOKIE_version $group { ~*v1$ host1; ~*v2$ host2; default default; } server { listen 99; #站点监听端口 server_name www.nginxtest.com; #服务启动后直接站点访问域名 charset utf-8; #编码格式,避免url参数乱码 location / { #proxy_pass http://MyServer; #映射到多个站点 proxy_pass http://$group; #根据COOKIE中version的值做对应的站点映射 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }