First, the premise
1: System Linux (CentOS)
2:nginx Proxy Server (web:192.168.1.10 proxy.abc.com)
3:nginx Background Server (web1:192.168.1.11 www.abc.com web2:192.168.1.12 backend.abc.com)
Second, configuration (192.168.1.10)
1: Configure/usr/local/nginx/config/nginx.conf
Remove server{} and introduce all server configurations via include config.d/*.conf
Add the following lines at the end of the nginx.conf:
ABC { 127.0. 0.1:8000; # # #通过IP # #127.0. 0.1:8001; server www.abc.com: 8000; # # #通过域名 # # server backend.abc.com:8001;} Include CONF.D/*. conf ;
2: Configuration
/usr/local/nginx/config/config.d/proxy.conf
Server {Listen the; server_name proxy.xiaohuideng.com; #charset Koi8-R; #access_log logs/Host.access.log Main; Location/{index index.html index.htm; proxy_set_header Host $http _host; # # #默认是以IP为负载 (Proxy_set_header Host $host;) Proxy_buffering off;
Proxy_set_header X-real-ip $remote _addr; # #不过滤掉真实请求IP地址 Proxy_pass http:// ABC; # # #引入upstream所定义的名字} error_page - 502 503 504/50x.html; Location= /50x.html {}}
Three, restart Nginx (192.168.1.10)
/USR/LOCAL/NGINX/SBIN/NGINX-T # #测试配置是否OK
/usr/local/nginx/sbin/nginx-s Reload # # #重新加载配置
Iv. Viewing effects
Visit http://proxy.abc.com on a remote PC browser to see if it gets backend.abc.com with Www.abc.com's page switch
Nginx Load Balancer Configuration One (reverse proxy)