AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 497462
Accepted
F21
F21
Asked: 2013-04-09 17:37:38 +0800 CST2013-04-09 17:37:38 +0800 CST 2013-04-09 17:37:38 +0800 CST

nginx gzip 启用但不是 gzipping

  • 772

我在 nginx 1.2.8 上启用了 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

配置:

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;

        }
    }
}

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

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

请求标头:

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

响应标头:

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

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


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

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  <---------------------

但是,如果我尝试使用 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

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

是什么原因造成的?

nginx
  • 2 2 个回答
  • 13073 Views

2 个回答

  • Voted
  1. Best Answer
    F21
    2013-04-09T20:49:30+08:002013-04-09T20:49:30+08:00

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

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

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

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

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

    • 9
  2. Marcel
    2013-04-09T18:00:06+08:002013-04-09T18:00:06+08:00

    尝试将默认类型更改为text/html- 的默认类型application/octet-stream不可压缩。

    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve