1

I have problems trying to set up a nginx reverse-proxy that preservers gzip compression.

My setup :

  • I have a CLoudfront distribution with gzip compression enabled (as you can see on http://dvty1uxa5ftxq.cloudfront.net my main.js is indeed compressed shrinking its size by more than 1/3).

  • Since some pages are redirected to another website, on my main website URL I am actually routing requests via nginx proxies, the relevant part of the config looks like

    server { listen 443 ssl; ... proxy_set_header X-NginX-Proxy true; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location @cloudfront { proxy_set_header Host $http_host; proxy_pass http://dvty1uxa5ftxq.cloudfront.net; } 

It would seem this is not enough to preverve gzip compression when a browser requests the website assets with proper accept headers specifying gzip. I am not knowledgeable enough with nginx to understand if I need to enable the gzip module or do anything. Most documentation I can find explain how to activate gzip encryption (eg for local files) but not when there's already a reliable gzip encryption performed by the proxied endpoint (here CloudFront).

Could anyone help me shed some light on this ?

1 Answer 1

0

From my understanding you must enable gzip and tell nginx it is okay to send compressed responses even if they are proxied.

location / { ... gzip on; gzip_proxied any; ... } 

See https://nginx.org/en/docs/http/ngx_http_gzip_module.htm for more documentation.

If you want to enable decompression for clients, that do not support gzip have a look at gunzip.

location / { ... gunzip on; ... } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.