Environment Introduction
192.168.127.131 nginx Load balancer and Web server
192.168.127.130 nginx Load balancer and Web server
Each server has two Web sites, respectively
Www.123.com
Www.hu.com
Description
Ready to useDNSPolling resolution for load balancing, and in twoServerIt's also enabled at the same timeNginxload Balancing, the two servers are mutually loaded. The premise is that two unitsWebthe Web site content of the service side is consistent.
Configuration process:
Operation on 130 load balancer:
Edit a configuration file above vi/usr/local/nginx/conf/vhost/ld.conf
## www. 123.com
upstream 123{ server 192.168.127.130:81; server 192.168.127.131:81 ; ip_hash ;} server { listen 80; server_name www.123.com; location / { proxy_pass http://www/; proxy_set_header host $ host; }}upstream hu { server 192.168.253.131:82; server 192.168.253.130:82; #dir ip_hash;} server { listen 80; server_name www.hu.com; location / { proxy_pass http:/ /aaa/; proxy_set_header host $host; proxy_ set_header x-real-ip $remote _addr; proxy_set_header X-Forwarded-For $proxy _add_x_forwarded_for; }
————————————————————————————————————————————————
Change Nginxload server above eachWebdefault port for host (Red Part font )
server{Listen 192.168.127.130:82; server_name www.hu.com; Index index.html index.htm index.php; root/usr/local/nginx/html; Location ~ \.php$ {include fastcgi_params; Fastcgi_pass Unix:/tmp/php-fcgi.sock; Fastcgi_index index.php; Fastcgi_param Script_filename/usr/local/nginx/html$fastcgi_script_name; }}
—————————————————————————————————————————————
server{Listen 192.168.127.130:81; server_name www.123.com; Index index.html index.htm index.php; ROOT/DATA/WWW2; Location ~ \.php$ {include fastcgi_params; Fastcgi_pass Unix:/tmp/php-fcgi.sock; Fastcgi_index index.php; Fastcgi_param Script_filename/data/www2$fastcgi_script_name; }}
131 The above configuration:
server{Listen 192.168.127.131:81; server_name www.123.com; Index index.html index.htm index.php; ROOT/DATA/WWW2; Location ~ \.php$ {include fastcgi_params; Fastcgi_pass Unix:/tmp/php-fcgi.sock; Fastcgi_index index.php; Fastcgi_param Script_filename/data/www2$fastcgi_script_name; }}
#####################################################################
server{Listen 192.168.127.131:81; server_name www.123.com; Index index.html index.htm index.php; ROOT/DATA/WWW2; Location ~ \.php$ {include fastcgi_params; Fastcgi_pass Unix:/tmp/php-fcgi.sock; Fastcgi_index index.php; Fastcgi_param Script_filename/data/www2$fastcgi_script_name; }}
#########################################################################################
the same in Edit a configuration file above vi/usr/local/nginx/conf/vhost/ld.conf
## www. 123.com
upstream 123{ server 192.168.127.130:81; server 192.168.127.131:81 ; ip_hash ;} server { listen 80; server_name www.123.com; location / { proxy_pass http://www/; proxy_set_header host $ host; }}upstream hu { server 192.168.253.131:82; Server 192.168.253.130:82; ip_hash;} server { listen 80; server_name www.hu.com; location / { proxy_pass http:/ /aaa/; proxy_set_header host $host; proxy_set_ header x-real-ip $remote _addr; proxy_set_header X-Forwarded-For $proxy _add_x_forwarded_for; }
Finally, start the Nginx service separately and see if the port starts properly.
Test: Add 1.txt Test files in the directory of two websites, write different content and then use the browser to access Www.hu.com/1.txt, refresh a few times
The same is true of Www.123.com/1.txt.
This article is from the "Drifting Away" blog, make sure to keep this source http://825536458.blog.51cto.com/4417836/1784794
How two servers do nginx load balancing with each other