nginx gzip 已启用但未启用 gzip

F21*_*F21 5 nginx gzip

我在 nginx 1.2.8 上启用了 gzip,但由于某种原因,它没有对任何东西进行 gzip。

Nginx 安装信息:

nginx version: nginx/1.2.8
built by gcc 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1) 
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.2.8 --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-pcre --conf-path=/etc/nginx/nginx.conf --add-module=../headers-more-nginx-module-0.19rc1
Run Code Online (Sandbox Code Playgroud)

配置:

user  www-user;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include mime.types;
    default_type  application/octet-stream;
    client_max_body_size 10M;

    sendfile        on;
    keepalive_timeout  65;

    more_clear_headers "Server";

    gzip  on;
    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;

    server {
        server_name test.com;
        root   /www;
        index index.php index.html index.htm;

        listen       80  default_server;

        rewrite ^/(.*)/$ /$1 permanent; #remove trailing slash

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        include      general/*.conf;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {

    fastcgi_intercept_errors on;

    fastcgi_pass   unix:/run/php/php-fpm.sock;

    fastcgi_index index.php;

    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    include        fastcgi_params;

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试发送一个简单的静态 css 文件。在我的 nginx 配置中,text/css包含在gzip_types.

当我尝试使用 Firefox 获取文件时,fiddler 显示接收到的内容未压缩:

请求头:

GET http://test.com/test.css HTTP/1.1
Host: nextdreamtest2.com
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: __utma=237624223.1052931239.1362029000.1365467381.1365469205.16; __utmz=237624223.1362029000.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utmc=237624223; __utmb=237624223
Proxy-Authorization: Basic cHJveHk6RTRRWlNlY0JLU3o0OFh4cWpLNkg=
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Run Code Online (Sandbox Code Playgroud)

响应头:

HTTP/1.1 200 OK
Date: Tue, 09 Apr 2013 01:35:07 GMT
Content-Type: text/css
Last-Modified: Thu, 31 May 2012 08:50:00 GMT
Connection: keep-alive
Content-Length: 1688
Run Code Online (Sandbox Code Playgroud)

请注意,Content-Encoding: gzip即使服务器上启用了 gzip ,也没有标头,并且内容类型是一种配置为 gzip 的。


经过更多的调查,我现在更加困惑了。我在运行 nginx 的机器(Ubuntu 12.10)上尝试了 FireFox 20.0,并且文件被正确压缩:

Connection  keep-alive
Content-Encoding    gzip <------------------------------
Content-Type    text/html
Date    Tue, 09 Apr 2013 04:23:08 GMT
Set-Cookie  200ceb26807d6bf99fd6f4f0d1ca54d4=7hjir1h44g3dq8hlsihdsrn9v5; path=/; HttpOnly
Transfer-Encoding   chunked  <---------------------
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试使用 IE10、FireFox 20 和 Chrome 26 以及 Fiddler 检查我的 Windows 8 机器上的标头以访问服务器,则响应永远不会被压缩!

Connection  keep-alive
Content-Length  2192 <------------------
Content-Type    text/html
Date    Tue, 09 Apr 2013 04:27:16 GMT
Run Code Online (Sandbox Code Playgroud)

这非常奇怪,因为我在 nginx.conf 中没有看到任何会歧视 Windows 8 机器的内容。

什么可能导致这种情况?

F21*_*F21 9

在看到 Ubuntu 上的 FireFox 20 能够接收 gzip 压缩的内容而我的 Windows 8 机器无法接收后,我开始怀疑。

它在我的 Windows 8 机器上尝试了以下内容:IE10、FireFox 20、Chrome 26、fiddler 和 curl。当他们显示他们收到了非 gzip 压缩的内容时,我立即怀疑我的互联网安全套件。

卸载 BitDefender Windows 8 安全后(它也没有最好的性能),我现在可以看到我的浏览器和我的 Windows 8 机器上的客户端接收 gzipped 内容。

BitDefender 可能正在解压缩我的数据包并在它攻击任何客户端之前分析它们是否有病毒和网络钓鱼材料。

尽管如此,在为此浪费了将近一天之后,我不会再安装它,而是会考虑其他产品。