Jer*_*rry 4 compression nginx gzip http-headers
在我的 nginx.conf 中,我有:
gzip on;
gzip_static on;
gzip_buffers 16 8k;
gzip_comp_level 9;
gzip_http_version 1.0;
gzip_min_length 1000;
gzip_types text/plain text/css image/x-icon image/bmp image/png image/gif image/jpeg image/jpg application/json application/x-javascript text/javascript;
gzip_vary on;
gzip_proxied any;
Run Code Online (Sandbox Code Playgroud)
所以,如果我在我的服务器上获取图片的标题:
spiroo@glamdring:~$ curl -I http://static.mysite.com/g/pics/big_6e1855d844ebca560379139e75942f669655f.jpeg
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 04 Apr 2013 13:00:20 GMT
Content-Type: image/jpeg
Content-Length: 5336
Last-Modified: Mon, 25 Mar 2013 13:28:02 GMT
Expires: Fri, 04 Apr 2014 13:00:20 GMT
Cache-Control: max-age=31536000
Pragma: public
Cache-Control: public, must-revalidate, proxy-revalidate
Accept-Ranges: bytes
Run Code Online (Sandbox Code Playgroud)
但是如果我在 nginx.conf 中关闭 gzip 压缩,我在 Content-Length 上得到完全相同的结果。
我究竟做错了什么?
提前致谢。
PS:需要明确的是,我有 nginx 最后一个版本,而且我支持代理(haproxy)。
编辑 ==>
我对 CSS 也有同样的问题。我知道 jpeg 已经被压缩了。当然,当我打开/关闭 gzip 时,我会重新启动 nginx。
这是我从 css 文件的标题中提取的内容。无论是否使用 gzip 压缩,我都有相同的 Content-Lenght。
spiroo@glamdring:~$ curl -I http://static.mysite.com/css/9a7f503b.css
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 04 Apr 2013 14:21:50 GMT
Content-Type: text/css
Content-Length: 203088
Last-Modified: Tue, 02 Apr 2013 11:34:39 GMT
Vary: Accept-Encoding
Expires: Fri, 04 Apr 2014 14:21:50 GMT
Cache-Control: max-age=31536000
Pragma: public
Cache-Control: public, must-revalidate, proxy-revalidate
Accept-Ranges: bytes
Run Code Online (Sandbox Code Playgroud)
这是我的静态文件的 nginx 配置:
server {
server_name static.mysite.com;
root /home/www/mysite/current/web;
location / {
return 404;
}
location ~ \.(?:jpg|jpeg|js|css|gif|png|swf|ico|pdf)$ {
expires 365d;
access_log off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
Run Code Online (Sandbox Code Playgroud)
}
curl
Accept-Encoding: gzip
默认情况下不会。您将需要使用-H "Accept-Encoding: gzip,deflate"
来获取 curl 来请求 gzip 或更好,使用--compressed
以便 curl 知道解压缩结果。
图片(jpg/gif 等)已经被压缩。因此您不需要(也不应该尝试)在 Web 服务器上压缩它们。
这是我压缩的示例:
gzip_types text/html text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20164 次 |
最近记录: |