Matching & Acting upon Headers received from Upstream with proxy_pass

Alec Muffett alec.muffett at
Thu Jan 31 21:06:10 UTC 2019

Hello All!

I'm running a reverse proxy and I want to trap when upstream is sending me:

  Content-Encoding: gzip

...and on those occasions return (probably) 406 downstream to the client;
the reason for this is that I am always using:

  proxy_set_header Accept-Encoding "identity"; the upstream should *never* send me gzip/etc; but sometimes it does
so because of errors with CDN configuration and "Vary:" headers, and that
kind of thing. I would like to make the situation more obvious and easier
to detect.

I have been trying solutions like:

  if ( $upstream_http_content_encoding ~ /gzip/ ) { return 406; }


  map $upstream_http_content_encoding $badness {
  br 1;
  compress 1;
  deflate 1;
  gzip 1;
  identity 0;
  default 0;
  server { ...
  if ($badness) { return 406; }

...but nothing is working like I had hoped, I suspect because I do not know
if/where to place the if-statement such that the
upstream_http_content_encoding is both set and valid during an appropriate
processing phase.

The most annoying thing is that I can see that the
upstream_http_content_encoding variable is set to "gzip", because if I do:

  more_set_headers "Foo: /$upstream_http_content_encoding/";

...then I can see the "Foo: /gzip/" value on the client; but that does not
help me do what I want.

Can anyone suggest a route forward, please?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list