Nginx load balancing

Note: In actual development, when the application is stored on multiple servers, it is necessary to use one server to be responsible for the role of load balancing; the
      configuration information enables the client to access one server attached to the following multiple services; the
effect : Alleviate the problem of insufficient corresponding capacity and high concurrency of a server;

1. Before the environment starts, prepare the same environment CentOS 6.5 used by four virtual machines.
  The access IPs of the external network of PHP 5.6 are:
  load balancing server-main: 192.168.147.135 
  server-1: 192.168.147.132
  server-2: 192.168. 147.133
  Server-3: 192.168.147.134
  The website application has deployed three servers and marked different information on the first page.
  
2. Modify and add nginx.conf configuration information /usr/local/nginx/conf/nginx.conf

  # Added upstream configuration information
  upstream test.nginx.com {
          server 192.168.147.132 weight=2; # weight indicates the weight of load distribution
          server 192.168.147.133 weight=2;
          server 192.168.147.134 weight=2;
  }  

  server{  
          listen 80;  
          server_name test.nginx.com;  
          # Add configuration item
          location / {  
                  proxy_pass http://test.nginx.com;  
                  proxy_set_header Host $host;  
                  proxy_set_header X-Real-IP $remote_addr;  
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
          }  
  }
  
3. After saving the above, restart the nginx service; after the
  restart is successful, visit test.nginx.com, refresh several times, you can see different home page information changes, indicating that the load balancing configuration is successful.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325911181&siteId=291194637