Give more than you planned to
Give more, don’t worry about
Nginx is powerful and often used as a reverse proxy or load balancing. When we deploy a web system, using nginx for load balancing is an affordable solution for increasing access traffic. This document is used to record nginx load balancing. Some operations.
In order to be more in line with the real environment, I have bound a domain name phantomjs.me on the local host, its ip address is 192.168.1.2, is a Linux server with nginx installed, used to simulate the load balancing server; There are also three web servers in the network, and their ips are 192.168.1.3, 192.168.1.4, and 192.168.1.5.
When we access the phantomjs.me domain name, the load balancing server can load traffic to three web servers, and the load can be freely selected.
- (A) 192.168.1.2 The load balancing server listens on port 80 and acts as a payload.
- (B) 192.168.1.3 Web server listens on port 80.
- (C) 192.168.1.4 Web server listens on port 80.
- (D) 192.168.1.5 Web server listens on port 80.
NOTE: The A server acts as a load balancing server, and the domain name is directly resolved to the A server (192.168.1.2:80). The traffic is load balanced by the A server to the B server (192.168.1.3:80), the C server (192.168.1.4:80), and the D server (192.168.1.5:80). Load balancing can be targeted at different servers or different ports on the same server, depending on actual needs.
Edit the nginx.conf of the A server. The file location is in the nginx installation directory, usually in /etc/nginx/nginx.conf. Add the following code in the http section:
Finally visit http://phantomjs.me
The default parameter after the upstream server weight=1 max_fails=1 fail_timeout=10s.
- weight: server weight
- max_fails=number: maximum number of failed attempts
- fail_timeout=time: set the length of time the server is unavailable
- backup: alternate host
- down: Manual tag no longer processes any user requests
Here, by the way, use nginx to configure the reverse proxy method. This method is also widely used in web hijacking (black production), which is not described in detail here.
Add the following to the server of the nginx configuration file:
Restart nginx, try to access http://phantomjs.me/update/, which actually gets the baidu update directory resource.
For more details on nginx load balancing, visit: http://www.jusene.me/2017/05/24/nginx-proxy/