问题描述
nginx gzip 配置如下:
gzip on;gzip_min_length 1k;gzip_buffers 4 16k;gzip_http_version 1.0;gzip_comp_level 2;gzip_types text/plain application/x-javascript application/javascript text/css application/xml;gzip_vary on;
用 curl 或 chrome 测试
$curl -I -H 'Accept-Encoding: gzip, deflate' 'http://localhost/template/tpl_header.php'HTTP/1.1 200 OKServer: Tengine/2.1.0Date: Sat, 05 Sep 2015 16:40:34 GMTContent-Type: text/htmlConnection: keep-aliveVary: Accept-EncodingX-Powered-By: PHP/5.5.27Content-Encoding: gzip
请求 jpg 图片则正常
curl -I -H 'Accept-Encoding: gzip, deflate' 'http://localhost/asset/image/common/bg.jpg'HTTP/1.1 200 OKServer: Tengine/2.1.0Date: Sat, 05 Sep 2015 16:43:36 GMTContent-Type: image/jpegContent-Length: 4817Last-Modified: Sat, 15 Aug 2015 13:12:10 GMTConnection: keep-aliveETag: '55cf3aaa-12d1'Expires: Mon, 05 Oct 2015 16:43:36 GMTCache-Control: max-age=2592000Accept-Ranges: bytes
请问这是什么原因?
附上编译参数:
./configure --prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --conf-path=/etc/nginx/nginx.conf --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --pid-path=/var/run/nginx.pid --with-cc-opt='-Wno-deprecated-declarations'
问题解答
回答1:因为你的php的header输出为text/html