Forward request headers from nginx proxy server Forward request headers from nginx proxy server nginx nginx

Forward request headers from nginx proxy server


If you want to pass the variable to your proxy backend, you have to set it with the proxy module.

location / {    proxy_pass                      http://example.com;    proxy_set_header                Host example.com;    proxy_set_header                HTTP_Country-Code $geoip_country_code;    proxy_pass_request_headers      on;}

And now it's passed to the proxy backend.


The problem is that '_' underscores are not valid in header attribute. If removing the underscore is not an option you can add to the server block:

underscores_in_headers on;

This is basically a copy and paste from @kishorer747 comment on @Fleshgrinder answer, and solution is from: https://serverfault.com/questions/586970/nginx-is-not-forwarding-a-header-value-when-using-proxy-pass/586997#586997

I added it here as in my case the application behind nginx was working perfectly fine, but as soon ngix was between my flask app and the client, my flask app would not see the headers any longer. It was kind of time consuming to debug.