我在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
configuration:
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文件。 在我的nginxconfiguration中, 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
请注意,即使在服务器上启用了Content-Encoding: gzip ,也没有Content-Encoding: gzip标头,而内容types是configuration为经过gzipconfiguration的。
经过更多的调查,我现在更加困惑。 我试着在机器上运行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能够接收gzip内容,而我的Windows 8机器无法使用,我变得可疑。
它在我的Windows 8机器上尝试了以下内容:IE10,FireFox 20,Chrome 26,fiddler和curl。 当他们显示他们收到了非gzip内容,我立即怀疑我的互联网安全套件。
卸载BitDefender的Windows 8安全(它没有最好的性能),我现在可以看到我的浏览器和我的Windows 8机器上的客户端接收gzip内容。
BitDefender可能会解开我的数据包,然后在遇到任何客户端之前分析它们中的病毒和networking钓鱼资料。
尽pipe如此,在浪费了将近一天的时间之后,我不会再重新安装它,而是在寻找另一种产品。
尝试将默认types更改为text/html – application/octet-stream的默认types不是gzipble。