PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 1, 2022

[FIXED] How to prevent nginx reverse proxy recompress the upstream compressed response?

 September 01, 2022     nginx, nginx-reverse-proxy, ngx-brotli     No comments   

Issue

I have nginx reverse proxy that receives brotli compressed response from upstream (Varnish cache). But, the reverse proxy serves brotli compressed response to browser only if I setup "brotli on;" within the reverse proxy server block.

My goal is to have the nginx reverse proxy not handle compression at all. To achieve this, I have following questions:

  1. Is the reverse proxy block expected to un-compress the received response and handle it on it's own? Can't it directly pass the upstream response back to client?

  2. Is there a way to dump proxy response or it's size to nginx logs? This shall help debug the issue better.


Solution

I have resolved this so posting this for anyone who may encounter similar issue:

  1. Varnish changed my 'Accept-Encoding' request header to 'gzip'. According to Varnish documentation, this is as designed (see here).
  2. However, the upstream nginx server (behind varnish) responded with non-compressed content because the default for gzip_http_version is 1.0 while the default for proxy_http_version is 1.1. (see here)

Resolution was achieved by:

a. setting Varnish to not worry about compression by passing -p http_gzip_support=off to varnishd.

b. setting gzip_http_version to 1.1 on the upstream Nginx server.

Deciphering the above behavior became possible because I logged the following on my upstream nginx server (the one behind varnish):

log_format bytes_sent '$bytes_sent' - '$http_accept_encoding' - '$request';


Answered By - Punit S
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing