About Nginx doing load balancing when backend server takes real IP

Source: Internet
Author: User

First: Nginx as loadblance to add the following configuration:

Proxy_set_header Host $host;

Proxy_set_header X-real-ip $remote _addr;

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

X-real-ip and X-forwarded-for can be 2 1 or open: more, view http://blog.chinaunix.net/u/32831/showart_1908231.html Then: 1. If backend is Apache: Apache needs to add a module RPAF

http://stderr.net/apache/rpaf/

Can be used with Apache 2.2 Compile and install for 1.3:apxs-i-a-c MOD_RPAF.C Compile and install for 2.0:apxs-i-c-n mod_rpaf-2. 0.so mod_rpaf-2.0.c or simply try:make Configuration directives:rpafenable on# Enable Reverse proxy add forwardrpafproxy_i PS 127.0.0.1 10.0.0.1# which IPS is forwarding requests to Usrpafsethostname on# let RPAF update vhost settings # allows To has the same hostnames as in the ' real ' # Configuration for the forwarding Apacherpafheader x-forwarded-for# allows To change which header MOD_RPAF looks# for when trying to find the IP the that's forwarding# our requests

# if DSO load module First:loadmodule rpaf_module libexec/apache2/mod_rpaf-2.0.so rpafenable on Rpafsethostname on RPAFPR Oxy_ips 192.168.1.23 (nginx loadblance server) Rpafheader x-forwarded-for

2. If it is nginx as backend words: Backend as the Nginx in the compilation need to add modules
--with-http_realip_module
and modify the nginx.conf:
Set_real_ip_from   192.168. 2. 1; (the IP is nginx loadblance IP)real_ip_header     x-real-ip;  
the context is: http, server, location

More, view:

Http://wiki.nginx.org/NginxHttpRealIpModule

About Nginx doing load balancing when backend server takes real IP

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.