Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check that the nginx gzip_static module is working?

Tags:

nginx

gzip

How can I check that nginx is serving the .gz version of static files, if they exist?

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).

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;

Any pointers would be appreciated.

like image 348
netflux Avatar asked Mar 17 '10 08:03

netflux


People also ask

What is Gzip_static Nginx?

gzip_static. The ngx_http_gzip_static_module module allows sending precompressed files with the “ . gz ” filename extension instead of regular files. This module is not built by default, it should be enabled with the --with-http_gzip_static_module configuration parameter.


2 Answers

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

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

As you can see, it is trying to find .gz versions of files.

like image 105
Milan Babuškov Avatar answered Oct 16 '22 16:10

Milan Babuškov


Change the content of the non-gzipped file. And then touch both files (simultaneously—that is: in the same instantiation of touch). If when you load the file in an browser (cache-wiped) you get the non-changed file, then nginx served the static-cached-gzipped file.

An easy way to avoid “did I just fetch the cache?” worries is to fetch from the command-line with curl since curl doesn’t cache.

like image 21
mxcl Avatar answered Oct 16 '22 17:10

mxcl