first Prepare 3 machines (VM VMS, of course), one to do load balancer server, 2 Web services, respectively installed Nginx, how to install nginx here is not in the narrative.
In addition, in order to test the smooth, please turn off the firewall of 3 machines first.
IP Planning:
equalization Machine: 10.1.1.10 | web-1:10.1.1.11 | web-2:10.1.1.12
The following configurations are made in nginx.conf
Load Balancer Server configuration
server 10.1.1.11 weight=1;
note: configuration should be within HTTP, outside of server, webservers this is an identity that is defined by itself for subsequent use. Weigth: Weight, the greater the value, the greater the chance of being redirected
Location /{#proxy实现反向代理
Proxy_pass http://webservers ; #将请求转发到上面upstream中配置的ip上
proxy_set_header x-real-ip $remote _addr; forwarded to the Web server on the #将请求源ip塞到header头中的X-real-ip, This sentence function in order to enable the Web server to obtain the real IP requested by the client
}
Web Server Configuration
set_real_ip_from 10.1.1.10; #负载均衡服务器IP
Real_ip_header X-real-ip;
Note: Add This 2 line configuration to get access to the real IP of the request, or you will always get the load Balancer server's IP, this configuration needs to compile nginx when adding --with-http_realip_ The module parameter succeeds or fails.
at this point to configure the wood has a ~ is not very simple, hurriedly to try a, instantly let you force lattice raise a lot Oh (*^__^*)
PostScript: For already installed Nginx machine but did not add --with-http_realip_module This compile parameter, can be added under the source code to add this parameter to compile, after configure Make ( do not install) , and then copy the OBJS below to overwrite the existing Nginx
Nginx Configuration Load Balancer (upstream) + reverse proxy (httpproxy)