自动gzip分别压缩每个文件

问题描述:

我们怎样才能在特定目录&它的子目录中分别压缩每个现有文件与自己的原始文件名。自动gzip分别压缩每个文件

这种方式我希望我们不需要每次为现有的nginx fastcgi缓存纯文本文件运行“即时gzip压缩”。

这可能会节省大量资源&也给我们提供低延迟/等待服务已缓存文件的时间。

+0

http://nginx.org/en/docs/http/ngx_http_gzip_static_module.html –

你需要自己压缩文件--Nginx不能帮你。对于所有要预先压缩的文件,只需将它们压缩并保存为“原始文件名+ .gz结尾”(位于同一目录中),然后使用gzip_static选项来提供这些文件。

所以这个工作的例子可能是:

http { 
    gzip on; 
    gzip_min_length 500; 
    gzip_proxied  any; 
    gzip_comp_level 4; 
    gzip_types text/plain text/xml application/xml application/json image/svg+xml image/x-icon image/gif text/css application/x-javascript; 
    gzip_vary on; 
    gzip_disable  "msie6"; 
    gzip_static on; # this enables the .gz files being served 

    ... here come your server blocks and other Nginx configuration 
} 

现在的.gz文件正在服役的所有gzip_types,如果存在的话 - 所有网站。如果您只想在某些目录/域中使用gzip_static,则可以在上面的http块中将其删除,并将其添加到位置块中 - 这是我通常所做的。