Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#1507 closed defect (duplicate)

gzip in if + proxy_pass doesn't work

Reported by: avkarenow@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.12.x
Keywords: Cc:
uname -a: FreeBSD 11.1-RELEASE-p4
nginx -V: nginx version: nginx/1.12.2
built with OpenSSL 1.0.2k-freebsd 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/etc/nginx --with-cc-opt='-I /usr/local/include' --with-ld-opt='-L /usr/local/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --user=www --group=www --modules-path=/usr/local/libexec/nginx --with-file-aio --http-client-body-temp-path=/var/tmp/nginx/client_body_temp --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp --http-proxy-temp-path=/var/tmp/nginx/proxy_temp --http-scgi-temp-path=/var/tmp/nginx/scgi_temp --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi_temp --http-log-path=/var/log/nginx/access.log --with-http_addition_module --with-http_auth_request_module --add-dynamic-module=/wrkdirs/usr/ports/www/nginx/work/headers-more-nginx-module-84241e4 --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_stub_status_module --with-http_sub_module --add-module=/wrkdirs/usr/ports/www/nginx/work/ngx_devel_kit-0.3.0 --add-dynamic-module=/wrkdirs/usr/ports/www/nginx/work/lua-nginx-module-0.10.8 --with-pcre --add-dynamic-module=/wrkdirs/usr/ports/www/nginx/work/passenger-5.1.11/src/nginx_module --with-http_v2_module --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-mail=dynamic --with-mail_ssl_module --with-http_ssl_module

Description

It's looking for me like a bug - when I'm using gzip in if in location and in this location is also proxy_pass - gzip doesn't compress requests.

For example:

gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml image/svg+xml;
gzip_disable msie6;
gzip_comp_level 6;

server {

listen 80;

location / {

set $g 1;
if ($g = "1"){ gzip on; }
set $z 1;
if ($z = "1") { set $b ""; }

proxy_set_header Host "...";
proxy_pass https://...;

}

}

The problem appears when the second if is true and only with proxy_pass (fastcgi_pass, uwsgi_pass, proxy_pass work correctly).

Change History (2)

comment:1 by Maxim Dounin, 7 years ago

Resolution: duplicate
Status: newclosed

That is because the request is processed in the context of the second "if", if ($z = "1") { set $b ""; }, and there is no gzip on in it. See http://wiki.nginx.org/IfIsEvil and ticket #86 for details. This particular case isn't really a bug, but rather a result of how if works, and the only solution would be to disallow the "gzip" directive in if.

comment:2 by avkarenow@…, 7 years ago

Thanks, I moved "if with gzip on" to the end of location and it solved my problem.

Note: See TracTickets for help on using tickets.