Nginx removes X-Client-IP header added by loadbalancer

Maxim Dounin mdounin at mdounin.ru
Mon Dec 10 00:47:08 UTC 2012


Hello!

On Sat, Dec 08, 2012 at 01:20:12PM -0500, mrtn wrote:

> Hi,
> 
> I have a HAProxy running in front of Nginx, and I add 'X-Client-IP' header
> to reflect the actual IP of the client. If the request is routed directly to
> the application server (Tornado in my case), this header is present and I
> can retrieve it with no problem.
> 
> However, if the request is first routed to Nginx and then to the application
> server using: 
> 
> proxy_pass              http://127.0.0.1:8080;
> proxy_redirect          off;
> 
> then the 'X-Client-IP' header is missing from the request when it reaches
> Tornado. I guess I might need to explicitly add this header in Nginx as
> well, so it can relay it on. What is the right solution here?

Most likely your balancer adds something like "X-Client_IP" instead, 
with "_"  (underscore) instead of "-" (dash).  Such headers are 
removed by nginx by default unless explicitly allowed, see

http://nginx.org/r/underscores_in_headers

You may either enable such headers in nginx (see above, but not 
recommended), or (better) change "_" to "-" in your balancer 
configs.

-- 
Maxim Dounin
http://nginx.com/support.html



More information about the nginx mailing list