I have the following setup and configured to send all /api requests to a different server:

location /api {
    proxy_pass              https://myapp.herokuapp.com;
    rewrite                 ^/api/(.*)              /$1     break;

My app sends a header (USER_CUSTOMER), when communicating directly with myapp.herokuapp.com from the app it works, but when requesting through the proxy server, the value appears NULL on the API Server.

The following works in NGINX, but I need the App to be able to set the value of USER_CUSTOMER.

location /api {
    proxy_pass              https://app.herokuapp.com;
    proxy_set_header        USER_CUSTOMER           ABC;
    rewrite                 ^/api/(.*)              /$1     break;

I may have additional headers to send in the future, so I'm hoping there is a flag to pass all headers from the proxy to the API Server.


The header attribute USER_CUSTOMER is invalid syntax. Underscores are not valid in header attributes.

There is a workaround but best solution is to rewrite the attribute to valid syntax.

Workaround is to set the following where you specify the server name in config:

underscores_in_headers on;
  • Not work in my case, the error log shows: nginx: [emerg] "underscores_in_headers" directive is not allowed here in nginx.conf:55 – thinkhy Apr 17 '16 at 13:21
  • 1
    thx this worked! – Magico Dec 12 '16 at 13:00
  • Worked!! But when request is called from the android app it shows me undefined. – Vishnu S Babu Nov 30 '17 at 7:04

I think you are looking for proxy_pass_request_headers option. Set it to on:

location /api {
    proxy_pass_request_headers      on;
    proxy_pass                      https://app.herokuapp.com;
    proxy_set_header                USER_CUSTOMER              ABC;
    rewrite                         ^/api/(.*)                 /$1     break;

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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