问题描述
如何检查nginx是否正在提供.gz版本的静态文件(如果存在)?
How can I check that nginx is serving the .gz version of static files, if they exist?
我使用gzip静态模块编译了nginx,但是我的日志中未提及.gz版本. (我将global.js和global.css文件缩小了,并将它们的.gz版本放在同一目录中.)
I compiled nginx with the gzip static module, but I don't see any mention of the .gz version being served in my logs. (I have minified global.js and global.css files with .gz versions of them in the same directory).
nginx.conf的相关部分如下所示:
The relevant part of nginx.conf looks like this:
gzip on;
gzip_static on;
gzip_http_version 1.0;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
任何指针将不胜感激.
推荐答案
使用strace.首先,您需要检测nginx进程的PID:
Use strace. First, you need to detect PID of nginx process:
# ps ax | grep nginx
25043 ? Ss 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
25044 ? S 0:02 nginx: worker process
好,所以25044是工作进程.现在,我们对其进行跟踪:
Ok, so 25044 is the worker process. Now, we trace it:
# strace -p 25044 2>&1 | grep gz
open("/var/www/css/ymax.css.gz", O_RDONLY|O_NONBLOCK) = 438
open("/var/www/css/patches/patch_my_layout.css.gz", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/var/www/yaml/core/iehacks.css.gz", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/var/www/js/koznazna5.js.gz", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/var/www/css/ymax.css.gz", O_RDONLY|O_NONBLOCK) = 216
如您所见,它正在尝试查找.gz版本的文件.
As you can see, it is trying to find .gz versions of files.
这篇关于如何检查nginx gzip_static模块是否正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!