如何告诉gzip_static不要查找图像文件? [英] How to tell gzip_static not to look for image files?

查看:80
本文介绍了如何告诉gzip_static不要查找图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已安装ggin_static激活的nginx.它适用于CSS和JavaScript文件,但也可以查找图像文件的压缩版本,例如.png和.gif,尽管这些文件不在要压缩的文件列表中:

I have nginx installed with gzip_static activated. It works fine for CSS and JavaScript files, but it also looks for gzipped versions of image files like .png and .gif, although these are not in the list of files to be compressed:

# strace -p 25044 2>&1 | grep gz
open("/var/www/css/ymax.css.gz", O_RDONLY|O_NONBLOCK) = 438
open("/var/www/images/tools.png.gz", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/var/www/images/ads/bs.gif.gz", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/var/www/images/gfxborder/border_right.gif.gz", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/var/www/images/ads/hocuto03.gif.gz", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)

这是我的nginx配置:

Here's my nginx configuration:

gzip  on;
gzip_disable     "msie6";
gzip_min_length 1000;
gzip_types text/plain text/css application/x-javascript text/javascript;
gzip_static on;

有办法防止这种情况吗?

Is there a way to prevent this?

推荐答案

我找到了解决方案.实际上,有两种可能的解决方案:

I found a solution. In fact, two possible solutions:

  1. 将javascript和CSS文件保存在单独的目录中,并创建位置"规则,仅将gzip_static用于该目录

  1. keep javascript and CSS files in a separate directory and create "location" rule to use gzip_static only for that directory

如果这是不可能的(托管多个网站,而不是您控制的所有内容,太多的目录和文件),那么有一种更简单的解决方案,可以使用

if this is not possible (hosting multiple websites, not everything under your control, too many directories and files) there is an easier solution to prevent multiple open() calls by using open_file_cache_errors setting which caches (i.e remembers) that .gz file was not present and does not try to open it again.

这篇关于如何告诉gzip_static不要查找图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆