Conditional access log formatting ?

Valentin V. Bartenev vbart at
Mon Jul 20 12:48:47 UTC 2015

On Saturday 18 July 2015 11:37:33 Ben wrote:
> Hi,
> I'm using haproxy infront of some NGINX instances, but only for some 
> instances which are being loadbalanced by haproxy, there are other 
> instances which go straight through.
> I realise I need to change the logging format in NGINX to enable 
> X-Forwarded-For in the access logs.
> The question is whether I can conditionally format the logs, i.e. use 
> "X-Forwarded-For" if it exists, otherwise use the normal NGINX logging 
> format.
> I've had a quick peek at the manual, I'm thinking maybe this can be done 
> with a map of some sort ?  Maybe there's a better way ?  To be honest 
> I've no idea where to start, and I've never used maps before anyway !

You should use the realip module:

  wbr, Valentin V. Bartenev

More information about the nginx mailing list