我的http块定义了各种gzip规则。 然后,在我已经预先压缩gzip文件的地方,我正在使用gzip_static模块。 即像这样的东西:
http { gzip on; #... server { #other vhost rules location /assets/ { gzip_static on; } } }
对于没有启动/断言的URL,nginx会发送头Content-Encoding: gzip 。 然而,像/assets/css/style.css这样的URL肯定会返回一个压缩的响应,但是没有Content-Encoding头。
这是预期的行为? nginx应该如何configuration?
只要用gzip_static打开它就不适合我。 在开始工作之前,我不得不使用gzip_proxied。
location /as/ { gzip_static on; gzip_proxied expired no-cache no-store private auth; gzip_min_length 500; # optional gzip_types text/plain application/xml text/css; # optional add_header Z_LOCATION "gz static location block"; add_header URI $uri; # DEBUG info }
注意最后一行增加了两个帮助debugging的头文件。 你可以使用Firefox的一个很棒的插件来看到这些,名为“Live HTTP Headers”,我发现它非常适合debugging标题和caching的负载。 请注意,“curl -I”不起作用,因为它不会发送标题,说它接受gzip编码。
您还应该确保文件具有相同的修改date
touch style.css style.css.gz
这里是我使用上面的位置configuration时返回的标题
HTTP/1.1 200 OK Server: nginx Date: Wed, 06 Jan 2016 20:07:18 GMT Content-Type: text/css Last-Modified: Wed, 06 Jan 2016 19:55:15 GMT Etag: "568d7123-84c" Z_LOCATION: gz static location block URI: /as/style.css Via: 1.1 BC5-ACLD Connection: Keep-Alive Content-Encoding: gzip Age: 0
我有一个location ~* \.(css|js|...) { expires 7d } block搞砸了。 我已经有了一个位置块玩,现在似乎都在工作。