我在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
配置:
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显示收到的内容不是gziped:
请求标题:
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标头,而content-type是配置为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机器的东西.
可能是什么导致了这个?
最佳答案
看到Ubuntu上的FireFox 20能够在我的Windows 8机器无法接收gzip压缩内容后,我开始怀疑.
原文链接:https://www.f2er.com/nginx/435287.html它在我的Windows 8机器上尝试了以下内容:IE10,FireFox 20,Chrome 26,小提琴和卷曲.当他们发现他们收到非gzipped内容时,我立即怀疑我的互联网安全套件.
在卸载BitDefender Windows 8安全性之后(它也没有最好的性能),我现在可以看到我的Windows 8机器上的浏览器和客户端接收到gzip压缩内容.
BitDefender可能会解压缩我的数据包,并在它遇到任何客户端之前分析它们是否存在病毒和网络钓鱼资料.
尽管如此,在浪费了将近一天之后,我将不会再次安装它并将查看另一种产品.