How to Remove Client Headers in Nginx before passing request to upstream server?

maddygoround picture maddygoround · Jun 14, 2017 · Viewed 31.2k times · Source

The Upstream server is wowza , which does not accept the custom headers if I don't enable them on application level.

Nginx is working as a proxy server, from the browser I want to send few custom headers which should be received and logged by Nginx Proxy but before forwarding request to upstream server those headers should be removed from the request.

So upstream server never come to know that there where any custom headers.

I tried proxy_hide_header as well as proxy_set_header "<header>" "" , but seems like they apply to response headers not the request headers.

And even if I accept to enable the headers on wowza, then again I am not able to find a way to enable headers at server level for all application. Currenlty I have to add headers to each newly created application which is not feasible for me to do.

Any help would be appreciated.

Answer

roryrjb picture roryrjb · Jun 14, 2017

The proxy_set_header HEADER "" does exactly what you expect. See https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header.

If the value of a header field is an empty string then this field will not be passed to a proxied server:

proxy_set_header Accept-Encoding "";

I have just confirmed this is working as documented, I used Nginx v1.12.