Deploy nginx load balancing of multiple servers in linux-linux system-pro-test effective

One, edit the nginx.conf file


 1. Modify the nginx .conf file

Enter the conf folder, cd  /usr/local/nginx/conf

Edit nginx .conf , vim  nginx .conf,   

     #keepalive_timeout  0;

    keepalive_timeout  65;

    #gzip  on;
       upstream ropservs{

                ip_hash;

                server 192.168.200.200:8081;
                server 192.168.200.201:8081;
                server 192.168.200.202:8081;
                server 192.168.200.203:8081;

                }

############################################################

        location / {

            proxy_pass        http://ropservs;

            proxy_set_header   Host    $host:$server_port;

            proxy_set_header  X-Real-IP        $remote_addr;

            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;

        }

2. Explanation:

      Among them, ip_hash; guarantees session consistency, which means that you are logging in to the server 192.168.200.200 this time, and ip_hash will ensure that the next time you log in, you will still operate on this server.

      Where server 192.168.200.200:8081;
                server 192.168.200.201:8081;
                server 192.168.200.202:8081;
                server 192.168.200.203:8081;

      For the deployed server address and port number, when a new server is deployed, add the new server address and port number. The port number generally defaults to 8081

       Modify location/content, where proxy_pass: reverse proxy, $server_port: the port monitored by nigix, and $proxy_port: the port that the server actually accesses

 Two, start and close nginx


  1. Start and close nginx

Enter this path:  cd  /usr/local/nginx/sbin

Start the nginx command:  ./nginx

Check the status of nginx : ps -ef|grep nginx will start successfully if master appears

Close nginx command :   kill -9 8725 ( there are three process numbers, the top process number) then close nginx 

Stop nginx command:  ./nginx -s stop 

Restart nginx command:   ./nginx -s reload

Guess you like

Origin blog.csdn.net/weixin_47055922/article/details/109236220