How to check if the nginx gzip_static module is working?

How can I verify that nginx serves .gz versions 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 that will be used in my logs. (I included the global.js and global.css files with their .gz versions in the same directory).

The corresponding 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.

+45
gzip nginx
Mar 17 '10 at 8:51
source share
6 answers

Use strace. First, you need to determine the PID of the 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 

So, 25044 is a workflow. Now we will 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.

+79
Oct 19 '10 at 20:48
source share

Change the contents of the file without gzip. And then touch both files (at the same time - that is: in the same instance of touch ). If when you download a file in the browser (caching), you get an immutable file, then nginx serves the file with the static gzip cache.

Easy way to avoid "I just popped the cache?" The concern is extracting from the command line using curl , since curl does not cache.

+19
Oct 22
source share

I would disable auto-compression and gzip_ratio :

 http { gzip off; gzip_static on; log_format log_with_ratio "... $gzip_ratio ..."; server { access_log /var/log/nginx/file.log log_with_ratio; } } 

Note that you can override gzip , gzip_static and access_log for each server level and location.

+15
Mar 19 '10 at 12:04
source share

There is some hint I noticed regarding the ETag response ETag .

If the static file is served by nginx, the header looks like this: ETag: "135a-BQhu6KL71dyeCXcVZme6ug" , however, when nginx compresses the response (via the gzip module), it looks like this: ETag: W/"135a-BQhu6KL71dyeCXcVZme6ug" (notification W/ ) .

You can use this as well as Content-Encoding: gzip to distinguish between simple static files, pre-compressed static files, and files compressed on the fly.

+1
Aug 01 '16 at 17:23
source share

You can use Chrome Dev tools through the Network tab if you have enabled the Content-Encoding column (right-click on the columns to enable / disable certain content in the table):

Chrome Dev Utilities with Content-Encoding Column Enabled Screenshot

-2
Apr 27 '16 at 17:22
source share

I usually use Chrome Dev tools and look at the file sizes for the corresponding files.

-3
Dec 19 '14 at 9:38
source share



All Articles