NGINX is not forwarding a header value when using proxy_pass
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.
Ubuntu
nginx/1.1.19
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;
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;
}