Nginx Configuration Load Balancer (upstream) + reverse proxy (httpproxy)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.