Nginx Reverse Proxy Server Load balancer architecture diagram (three servers as an example)
Nginx Server Load balancer (figure: 192.168.1.1: 80 server configuration) 192.168.1.1: 80 virtual host role 192.168.1.1: 80 virtual host is configured based on nginx. The main role here is WebServer and Server Load balancer, the server Load balancer module uses the upstream module to receive client requests and distribute requests based on backend servers, it provides a simple method to reverse proxy client requests to the virtual host listened to by the backend server, implementing Server Load balancer commands.
Syntax: SERVER_NAME [parameters] environment: upstream function: This command specifies the name and parameters of the backend server. The server name refers to the virtual host listened to by nginx or Apache. It can be a domain name, IP address, port number, or UNIX socket parameter: Weight = [number]: sets the weight of the server. The higher the weight, the more client requests are distributed to max_fail = [number]: the number of failed requests to the backend server within the time specified by the fail_timeout parameter. Fail_timeout = [time]: After the number of failed times set by the max_fail parameter is reached, the pause time is down: Mark the server as a permanent offline backup: enabled only when all non-backup servers are down or busy
Upstream sample configuration
upstream icontact_pool {server192.168.1.1:9000weight=5max_fails=3fail_timeout=20s;server192.168.1.2:9000weight=3max_fails=3fail_timeout=20s;server192.168.1.3:9000weight=2max_fails=3fail_timeout=20s;}Ngxin VM Server Load balancer Configuration
Server {listen192.168.1.1: 80; server_name192.168.1.1; access_log/var/log/nginx/balance/loadbalance. access. log; error_log/var/log/nginx/balance/loadbalance. error. log; # Allow the column directory location/{root/balance/; autoindexon; autoindex_exact_sizeoff; autoindex_localtimeon; allow;} # proxy the PHP scripts to fpm_pool_upstreamlocation ~ \. Php $ {root/balance; Include/etc/nginx/fastcgi_params; # Load Balancing client requests received by webserver to the pool fastcgi_passicontact_pool ;}}The server Load balancer server processes PHP request roles 192.168.1.1: 9000, 192.168.1.2: 9000, and 192.168.1.3: 9000, which are the FPM addresses and port numbers listened to by the three backend server Load balancer servers, the server Load balancer server sends the HTTP request and context parameters to the FPM pool through FastCGI. Then, FPM is responsible for parsing the PHP program. Note that the three servers must ensure that the PHP root directory has the PHP file required by the client, otherwise, a 404 error will occur!