upstream backend { server backend1.example.com weight=5; server backend2.example.com:8080; server unix:/tmp/backend3; server backup1.example.com:8080 backup; server backup2.example.com:8080 backup; } server { location / { proxy_pass http://backend; } }
[root@lb01 ~]# vim /application/nginx/conf/nginx.conf sendfile on; keepalive_timeout 65; upstream backend { server 10.0.0.7:80 weight=1; server 10.0.0.8:80 weight=1 backup; } server { listen 80; server_name www.etiantian.org; location / { proxy_pass http://backend; proxy_set_header Host $host; } } server { listen 80; server_name blog.etiantian.org; location / { proxy_pass http://backend; proxy_set_header Host $host; } } }
10.0.0.5 www.etiantian.org blog.etiantian.org
for n in {1..100};do curl www.etiantian.org;sleep 1;done
在nginx反向代理服务器上配置nginx文件,添加获取用户ip的字段:proxy_set_header X-Forwarded-For $remote-addr;
在web服务器的日志配置接收字段:http_x_forwarded-for;
lb01(负载均衡):
web01(节点服务器):
测试:
web01:
tail -f /application/nginx/logs/access_www.log
这时用电脑访问www.etiantian.org
max和fail的默认值
====================================================================================================================================