I have the following conf on nginx:

location ~* ^/assets/ {
    add_header Access-Control-Allow-Headers content-type;
    add_header Access-Control-Allow-Origin *;
    add_header Cache-Control "public, max-age=31536000";
    proxy_pass http://nas-mydomain.com;
    proxy_next_upstream http_500 timeout;
    gzip_http_version 1.0;
    gzip_static always;
    gzip_vary on;
    etag on;

My goal is to serve the static content in that folder in gzipped form when available.

I of course created files like:


I can reach each file and all the headers are correctly set as well as the etags. However, the gzip retrieving is not working. For example, I tested it like this:

curl -H "Accept-Encoding: gzip" http://domain.com/assets/test.js | gunzip
## Cutted useless output
gunzip: unknown compression format

So I guess that is not working. I also tried to listen with:

strace -p pid1 -p pid2 -p pid3.... 2>&1 | grep gz

with no luck.

And, of course, if I do:

curl http://domain.com/assets/test.js.gz | gunzip
## Cutted useless output

everything works perfectly.

Any hints?

nginx -v = nginx version: nginx/1.8.0 
#--with-http_gunzip_module --with-http_gzip_static_module are present
  • 2
    You proxy request to another server. gzip_static works only with local files. That means, you have to configure remote server to serve gzipped content. – Alexey Ten Jul 16 '15 at 8:16

you're doing proxy_pass, that's the problem. serve those files from server itself, i.e. using "root /some/path" directive, and everything should work.

  • oh yes thanks this is working i made another location without proxy pass and i got the reply that i was looking for. – Andrea Ferraresi Jul 16 '15 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.