安装忽略
配置niginx.conf(轮询模式)注意:下面的配置要放在http模板里面否则会报错
upstream cs_web{ server 192.168.31.204:80; server 192.168.31.203:80; } server { listen 80; server_name 192.168.31.200; location / { proxy_pass http://cs_web; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; index index.html index.htm; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
轮询加权模式(weight为权重)
upstream cs_web{ server 192.168.199.204:80 weight=3; server 192.168.199.203:80 weight=10; }
ip_hash模式(解决用户第二次登陆,登陆信息会丢失的解决方法,但nginx必须是前端和唯一的负载均衡器才能有用)
upstream cs_web{ ip_hash; server 192.168.199.204:80; server 192.168.199.203:80; }