Client-IP HTTP header to X-Forwarded-For

Igor Sysoev is at
Thu May 3 22:54:13 MSD 2007

On Thu, May 03, 2007 at 06:07:37PM +0100, Mike wrote:

> Igor Sysoev wrote:
> >On Thu, May 03, 2007 at 03:31:44PM +0100, Mike wrote:
> >
> >>Client requests are through virtual IP's that are handled by a hardware 
> >>load balancer, and then passed onto the real servers on the backend. The 
> >>source IP from the client is NAT'd so that all IP's appear to originate 
> >>from the load balancer. Responses from the real servers are sent back 
> >>via the load balancer to the client.
> >>
> >>On the load balancer, I have enabled, in the configuration, that a 
> >>header be added by the load balancer and passed onto the server that is 
> >>running Nginx (version 0.5.19). The request header that is added and 
> >>passed out to the real server, is as follows:
> >>
> >>Client-IP: myip
> >>
> >>Is there any way to get Nginx to log this IP as the remote_addr or as 
> >>X-Forwarded-For so that the PHP application that Nginx is passing 
> >>requests to will log the real source IP? I realise that there have been 
> >>posts in the past but I have not been able to figure this out.
> >
> >This header is available in nginx as $http_client_ip.
> >
> >You can describe it in log_format instead of $remote_ip
> >and you pass it to FastCGI:
> >
> >fastcgi_param  REMOTE_ADDR        $http_client_ip;
> >
> >
> Hi Igor
> Thanks for the fast and accurate response.
> I did a search against the $http_client_ip string on the wiki and 
> nothing showed up, so unless anyone has any objections, I'll add this 
> with my use-case scenario.

All client headers are available as $http_... variables.
For example, "X-Strange-Header" as $http_x_strange_header.

Igor Sysoev

More information about the nginx mailing list