#965 closed defect (invalid)
gzip_static isn't working with proxy_pass
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | nginx-module | Version: | 1.9.x |
Keywords: | gzip_static | Cc: | |
uname -a: | MINGW32_NT-6.1 S34D00D 1.0.18(0.48/3/2) 2012-11-21 22:34 i686 Msys | ||
nginx -V: |
nginx version: nginx/1.9.15
built by cl 16.00.30319.01 for 80x86 built with OpenSSL 1.0.2g 1 Mar 2016 TLS SNI support enabled configure arguments: --with-cc=cl --builddir=objs.msvc8 --with-debug --prefix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --http-scgi-temp-path=temp/scgi_temp --http-uwsgi-temp-path=temp/uwsgi_temp --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=objs.msvc8/lib/pcre-8.38 --with-zlib=objs.msvc8/lib/zlib-1.2.8 --with-select_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-mail --with-stream --with-openssl=objs.msvc8/lib/openssl-1.0.2g --with-openssl-opt=no-asm --with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_module --with-ipv6 |
Description
I've been trying to get gzip_static working for a few days now. It appears that it only works for location's configured for direct serving of content (i.e. with a root) versus location's with a proxy_pass.
For instance, here's a portion of my nginx.conf file:
# ROOT_LOCATION location / { gzip on; gzip_comp_level 6; gzip_vary on; gzip_min_length 1000; gzip_proxied any; gzip_types text/plain text/html text/css application/json text/javascript application/javascript application/x-javascript text/xml application/xml application/xml+rss; gzip_buffers 16 8k; proxy_pass http://localhost:3001/; } ## GZIPPED_ABSOLUTE - WORKS - C:/WS/application is where http://localhost:3001 is rooted #location /dist/gzipped { # gzip_static on; # root C:/WS/application; #} ## GZIPPED_PROXIED - DOESN'T WORK!! #location /dist/gzipped { # gzip_proxied any; # gzip_vary on; # gzip_static on; # proxy_pass http://localhost:3001/dist/gzipped; #}
I have both a boot.js file and a boot.js.gz version of the same file under C:/WS/application/dist/gzipped.
- Requesting boot.js with the "Accept-Encoding: gzip" header and ONLY the ROOT_LOCATION section of the config un-commented results in the boot.js file being compressed on the fly (this can be verified by changing the gzip_comp_level) and being returned with "Content-Encoding: gzip" and "Content-Type: application/javascript" among other things.
- Requesting boot.js with the "Accept-Encoding: gzip" header and BOTH the ROOT_LOCATION and the GZIPPED_ABSOLUTE sections of the config un-commented results in the compressed boot.js.gz file being returned. This can be verified by checking the "Content-Length" header against the size of boot.js.gz.
- Requesting boot.js with the "Accept-Encoding: gzip" header and BOTH the ROOT_LOCATION and the GZIPPED_PROXIED sections of the config un-commented results in the un-compressed boot.js file being returned. This can be verified by checking the "Content-Encoding" header and seeing that the response was not gzipped as well as checking the "Content-Length" header against the size of boot.js.
List item 3 is where my problem and I believe a bug lies. I've verified that the version of nginx that I'm running was compiled with the --with-http_gzip_static_module option. Additionally, I've enabled writing to the error_log at the debug level. I see entries related to http static show up with the GZIPPED_ABSOLUTE section enabled, but not when I have the GZIPPED_PROXIED section enabled.
Please help!
Thanks!
Change History (6)
comment:1 by , 9 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 9 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Unfortunately, including gzip_http_version with either a value of 1.0 or 1.1 doesn't affect the outcome at all.
comment:3 by , 9 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Well, it looks like I incorrectly understood your problem. You are trying to use gzip_proxied
and proxy_pass
in the same location, and this isn't expected to work either. Documentation says:
The ngx_http_gzip_static_module module allows sending precompressed files with the “.gz” filename extension instead of regular files.
That is, gzip_static
is only expected to work when nginx is about to return regular files. It's not expected to do anything when all requests are proxied to an upstream server as happens with proxy_pass
. If you are using proxy_pass
, you have to the gzip_static
on the upstream server, where the file itself is returned (and on this upstream server you'll have to configure various gzip_*
directive correctly as well, including gzip_http_version
and gzip_types
).
As previously suggested, please use mailng lists if you have additional questions.
comment:4 by , 9 years ago
Thanks for the slight clarification. Why then would you ever use gzip_proxied with gzip_static?
follow-up: 6 comment:5 by , 9 years ago
The gzip_proxied
is not about proxy_pass
, but about requests which was got by nginx from other proxy servers (as indicated by Via
header). In particular, it's unsafe to return gzipped content to proxy servers when using HTTP/1.0 or not using Vary
with HTTP/1.1.
Most likely, your problem is gzip_http_version.
If you have additional questions, please use mailng lists instead.