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:
test.js
test.js.gz
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
Best Answer
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.