nginx 配置 gzip无效

580 views
Skip to first unread message

Tim Yang

unread,
Sep 2, 2014, 10:55:01 AM9/2/14
to open...@googlegroups.com
春哥!

我在nginx中配置 gzip, 配置如下
  location /test/ {
     gzip on;
     gzip_min_length 1k;
     gzip_buffers 4 16k;
     gzip_http_version 1.1;
     gzip_comp_level 2;
     gzip_proxied expired no-cache no-store private auth;
     gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
     gzip_vary off;

    root /data;
    autoindex on;
}

而且已经验证过  nginx的模块中包含--with-http_gzip_static_module,, 是使用./configure --with-http_gzip_static_module 的方式配置,然后make , make install

但为什么我访问 curl -I -H "Accept-Encoding: gzip, deflate" "http://www.xxx.com/test/1000.png"
仍旧显示非压缩模式!返回结果如下!
 

HTTP/1.1 200 OK
Server: openresty/1.5.11.1
Date: Tue, 02 Sep 2014 14:42:54 GMT
Content-Type: image/png
Content-Length: 18918
Connection: keep-alive
Last-Modified: Mon, 01 Sep 2014 10:56:10 GMT
ETag: "540450ca-49e6"
Accept-Ranges: bytes

Zhao Xiaohong

unread,
Sep 2, 2014, 11:10:23 AM9/2/14
to open...@googlegroups.com
On Tue, Sep 2, 2014 at 10:55 PM, Tim Yang <tim.i...@gmail.com> wrote:
但为什么我访问 curl -I -H "Accept-Encoding: gzip, deflate" "http://www.xxx.com/test/1000.png"
仍旧显示非压缩模式!返回结果如下!
 

HTTP/1.1 200 OK
Server: openresty/1.5.11.1
Date: Tue, 02 Sep 2014 14:42:54 GMT
Content-Type: image/png
Content-Length: 18918
Connection: keep-alive
Last-Modified: Mon, 01 Sep 2014 10:56:10 GMT
ETag: "540450ca-49e6"
Accept-Ranges: bytes

curl -I -H "Accept-Encoding: gzip, deflate" "http://www.xxx.com/test/1000.png"

使用了 -I, --head Show document info only 参数,这个参数会使得 curl 发起的 HTTP Method 为 HEAD,而不是 GET。(可使用 curl 的 -v 参数查看发送的详细请求信息)。

HEAD 请求没有 body,所以没有对 body 做 gzip。

--
* Zhao Xiaohong

Tim Yang

unread,
Sep 2, 2014, 11:16:48 PM9/2/14
to open...@googlegroups.com
谢谢。。Zhao Xiaohong 

我用这个命令尝试

返回结果

 HTTP/1.1 200 OK
Server: nginx
Date: Wed, 03 Sep 2014 03:15:27 GMT
Content-Type: image/png
Last-Modified: Thu, 23 Aug 2012 13:50:53 GMT
Connection: keep-alive
Expires: Fri, 03 Oct 2014 03:15:27 GMT
Cache-Control: max-age=2592000
Content-Encoding: gzip

是有gzip 信息的。。你可以尝试下,,这个地址可以任意访问 

Tim Yang

unread,
Sep 2, 2014, 11:50:51 PM9/2/14
to open...@googlegroups.com
谢谢。。Zhao Xiaohong 

我已经发现问题了。 我使用了反向代理, 

 gzip_http_version 1.1;   这个应该配制成  gzip_http_version 1.0;
Reply all
Reply to author
Forward
0 new messages