Nginx做负载均衡

只需要3步:

1、在nginx.conf中的http段增加upstream服务器

    upstream backend{  
        server 192.168.140.15:18080 weight=2;  
        server 192.168.140.81:18080;  
        server 192.168.140.82:18080;  
    }

2、在nginx.conf中的http段增加server

    server {
        listen       18080;
        server_name  localhost;

        location / {
            proxy_pass http://backend/;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

3、重启Nginx

Comments are closed.