Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I have the following example

           location / {
                    proxy_read_timeout 2000;
                    proxy_next_upstream error;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host $http_host;
                    proxy_pass_header X_CUSTOM_HEADER;
                    proxy_redirect off;
                    proxy_max_temp_file_size 0;
                    proxy_pass https://prod;

Now when i use the following curl line

curl --head -H "X_CUSTOM_HEADER: foo"

Now that does not work.. the apache/php on the backend doesn't see the header. If I bypass nginx it works

curl --head -H "X_CUSTOM_HEADER: foo"
share|improve this question
up vote 9 down vote accepted

You should use underscores_in_headers on directive which is off by default.

share|improve this answer
that was it! thanks! – Mike Aug 5 '11 at 12:54
This info saves me hours. – Morgan Cheng Dec 27 '13 at 5:33

You should use proxy_set_header for all headers you wish to forward to the backend servers. So instead of proxy_pass_header ... line:

proxy_set_header X_CUSTOM_HEADER $http_x_custom_header;
share|improve this answer
I have tried that and it doesn't set the header correctly, If i replace $http_x_custom_header with "foo" it works – Mike Aug 3 '11 at 21:23
I'm not sure why it didn't work for @Mike but it did work for me. I am using X-Forwarded-Proto with $http_x_forwarded_proto. – Tyler Collier Jul 9 '14 at 21:43

The above didn't work for me either so I used proxy_pass_header. See the Nginx Wiki about proxy_pass_header here.

If your custom header is device_id add proxy_pass_header device_id; to your Proxy block.

If you are using customheaders with an underscore in it (like I am) be sure to make sure you have underscores_in_headers on in your Nginx Config.

share|improve this answer

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.