Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What can I use in the nginx config to make it clear any existing X-Forwarded-For headers before setting its own? I am currently using Nginx to terminate SSL before passing traffic to HAProxy to load balance.

Right now, I have:

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

This will append a new IP address to the end of any existing X-Forwarded-For IP addresses however. Is there a way to only keep the address seen by Nginx?

share|improve this question
up vote 7 down vote accepted

Just don't use $proxy_add_x_forwarded_for - the whole purpose that it exists is to do the appending behavior.


proxy_set_header X-Forwarded-For $remote_addr;
share|improve this answer
Works! Thanks a lot! – sidprak Apr 6 '12 at 1:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.