wingoo
wingoo

Reputation: 41

nginx gzip not working on browser but curl works

my environment is nginx(1.3.11) + php-fpm

curl -I -H "Accept-Encoding: gzip,deflate" http://www.ihezhu.com/

the result is

HTTP/1.1 200 OK  
Server: nginx  
Date: Wed, 03 Jul 2013 07:47:27 GMT  
Content-Type: text/html; charset=utf-8  
Connection: keep-alive  
Vary: Accept-Encoding  
Set-Cookie: PHPSESSID=st7oa6mero58n6lmitlofa4n70; path=/  
Expires: Thu, 19 Nov 1981 08:52:00 GMT  
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0  
Pragma: no-cache  
Content-Encoding: gzip

but when i use browser like chrome and the response doesn't contain gzip
[there's a special case : when open http://www.ihezhu.com/list/md_area-c_beijing/f_2000.3000_0_0_0_0_0_0_0.0.0.0.0_0_0-s_time_asc-lt_list-p_1/ , it's response gzip T_T]

what's wrong?

my nginx setting is

gzip on;  
gzip_buffers 4 16k;  
gzip_comp_level 3;  
gzip_http_version 1.1;  
gzip_min_length 1k;  
gzip_proxied any;  
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;  
gzip_vary on;  
gzip_disable msie6;

thanks

my nginx compile options, nginx virson now update to 1.5.2

./configure \  
    --pid-path=/var/run/nginx.pid \  
    --lock-path=/var/lock/nginx.lock \  
    --user=nginx \  
    --group=nginx \  
    --with-http_realip_module \  
    --with-http_gzip_static_module \  
    --with-http_stub_status_module \  
    --with-pcre=/var/src/pcre-8.33 \  
    --with-zlib=/var/src/zlib-1.2.8 \  
    --http-client-body-temp-path=/var/tmp/nginx/client \  
    --http-proxy-temp-path=/var/tmp/nginx/proxy \  
    --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \  
    --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \  
    --http-scgi-temp-path=/var/tmp/nginx/scgi

update info

the url http://www.ihezhu.com/list and http://www.ihezhu.com/list/md_area-c_shanghai/f_0.0_0_0_0_0_0_0_0.0.0.0.0_0_0-s_time_asc-lt_list-p_1/ has same response content, but only the long one has gzip..

Upvotes: 1

Views: 3490

Answers (1)

Chuan Ma
Chuan Ma

Reputation: 9914

  • Your curl command works because it sends a HEAD request, instead of a GET request. Try curl with verbose mode:

    curl -Iv -H "Accept-Encoding: gzip,deflate" http://www.ihezhu.com/

You will get the same result as in browser with

curl -i -H "Accept-Encoding: gzip,deflate" http://www.ihezhu.com/
  • "text/html" is always compressed. So it has nothing to do with gzip_types directive.

  • This happened to me before when my upstream server was using http 1.0 instead of http 1.1. Have you tried the following?

    gzip_http_version 1.0;

[update] Your nginx compile option seems normal. It's hard to understand how url length directly affects nginx on gzip. Checked the nginx source code. nothing on url is used to determine gzip. Based on the source code, there are 2 possible causes:

  1. Your php code returns a non-empty content-encoding header with the short url request.
  2. Your php code returns a wrong content-length header with the short url request, and that length is smaller than 1k.

So the best way is to find the php response header of both urls and start from there.

Upvotes: 3

Related Questions