Schematic diagram of Nginx load balancing:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7F/E0/wKiom1cwXU-BvFj9AACDm7MqUAQ203.png "title=" 6xwxzuk%z~d_]1d[h7jj5t.png "alt=" Wkiom1cwxu-bvfj9aacdm7mquaq203.png "/>
Site content is deployed on apache1 and apache2, load balancing on Nginx, when users want to access apache1 and apache2 the content on the server, only need to access the Nginx server, Nginx will forward the request to the Web server apache1 and apache2, the Web server after processing the request, the content of the request sent to Nginx, Nginx then return the content to the user there.
This forwarding process, for the user is not feel, can not only protect the Web server security, but also improve the performance of the Web server.
How to set Load balancing:
, there is an Nginx server (192.168.1.100) and two Web servers (192.168.1.101/192.168.1.102)
Modify the contents of the home page file on two Apache servers, respectively:
This is A.
This is B.
Simply modify the configuration file in Nginx nginx.conf as follows:
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
upstream Web1 {
Server 192.168.1.101:80 weight=1 max_fails=2 fail_timeout=30s;
Server 192.168.1.102: weight=1 max_fails=2 fail_timeout=30s;
}
#web1 Load Module name (custom).
# Weight weights, the higher the value the greater the priority.
#max_fails the maximum number of failures, the list of loads is excluded if the host fails to connect two consecutive times.
#fail_timeout the wait time for the request to fail.
server {
Listen 80;
server_name localhost;
Location/{
Proxy_pass http://web1;
root HTML;
Index index.html index.htm;
}
}
}
#proxy_pass Http://web1; Enable the load module.
Restart the Nginx service after saving the exit.
With access to 192.168.1.100, the load balancer builds successfully if the contents of the two Apache servers are displayed separately.
Nginx Load balancer (based on ip/port)