Conditionally removing a proxy header

Francis Daly francis at daoine.org
Thu May 14 22:08:21 UTC 2020


Hi there,

I'm not certain why you want to do the specific example that you want
to do; but if I were doing the general "conditionally remove header"
thing, I would probably use "map" to set a new variable "$my_value"
based on your variable "$external_traffic".

If $external_traffic is 1, set $my_value to blank.

Otherwise, set $my_value to $upstream_http_www_authenticate.

And then always "proxy_hide_header WWW-Authenticate;" and
"add_header WWW-Authenticate $my_value always;"

If the value is blank, add_header does not write the header. And "always"
is because you probably only get the WWW-Authenticate on a 401 response.

http://nginx.org/r/map
http://nginx.org/r/$upstream_http_
http://nginx.org/r/add_header

(Note the standard caveats about directive inheritance, particularly
regarding add_header, if that applies in your config.)

Hope this helps!

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list