Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 938
maddygoround Avatar asked Jun 14 '17 05:06

maddygoround


People also ask

Does nginx pass headers?

By default, nginx does not pass the header fields “Date”, “Server”, “X-Pad”, and “X-Accel-...” from the response of a proxied server to a client.

What is Proxy_hide_header in nginx?

If you want to hide headers from upstream servers you need to use proxy_hide_header . The Server header is not passed to the response sent to a client by default, as Date , X-Pad , and X-Accel-... headers.

What is Proxy_buffering in nginx?

Proxy buffering is enabled by default in NGINX (the proxy_buffering directive is set to on ). Proxy buffering means that NGINX stores the response from a server in internal buffers as it comes in, and doesn't start sending data to the client until the entire response is buffered.

What is upstream client in nginx?

upstream defines a cluster that you can proxy requests to. It's commonly used for defining either a web server cluster for load balancing, or an app server cluster for routing / load balancing.


1 Answers

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.

like image 125
roryrjb Avatar answered Oct 15 '22 09:10

roryrjb