Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm currently trying to set up Nginx to serve all of my static files. Since they will not be changed very frequently at all I want to us the gzip_static module to allow me to pre-gzip copies of my files to save some cpu time and allow better compression.

I Compiled Nginx with --with-http_gzip_static_module and set it up so that it is serving my static files, no problems so far. I wanted to test and make sure that the static gzipping was actually working, so I made two files, test.txt and test.txt.gz. The first line of each of the files says whether they were gzipped, and then there's a newline and 256 random characters (different betweeen the two files).

I've read that the modification time of the file and it's gzipped counterpart should be the same, and I've tried both of the following:

touch test.*
touch -r test.txt test.txt.gx

On my local machine, I'm testing with curl:

curl $URL/test.txt

This works fine, I get back the version that I didn't pre-compress, but when I do this:

curl -H "Accept-Encoding: gzip" $URL/test.txt | gunzip

I also get back the version I didn't precompress. I tried setting gzip off in my nginx.conf, but it doesn't make a difference. I've also re-compiled Nginx with --without-http_gzip_module and that doesn't seem to make a difference either, Nginx still gzips things itself on the fly.

I'm quite new to Nginx, but I'm really at a loss here.

Here is the output of ./nginx -V

built by gcc 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) 
configure arguments: --sbin-path=$SOMEPATH/nginx --prefix=$SOMEPATH --user=$ME --group=$MYGROUP --with-http_gzip_static_module --without-http_gzip_module

And here is my nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
error_log  logs/error.log;
pid        logs/nginx.pid;
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    gzip_static on;
    sendfile        on;
    keepalive_timeout  65;
    access_log  logs/access.log;
    server {
        listen       XXXX;
        server_name  foo.bar.com;
        location / {
            root   html;
        }
        error_page  404 404.html;
        error_page   500 502 503 504 50x.html;
    }
}

Any help is very appreciated!

share|improve this question

1 Answer 1

up vote 6 down vote accepted

You didn't mention this in your question, but I have it on good authority that you are running Nginx proxied behind another Nginx on a shared host. ;)

Nginx's gzip modules use HTTP 1.1 by default, but Nginx can only use HTTP 1.0 when communicating with back-end servers, so the solution is to set gzip_http_version in your nginx.conf, like so:

gzip_http_version 1.0;

Restart your Nginx after making that change, and you should be in business.

share|improve this answer
    
Amazing! How did you know this? –  Pineapple Under the Sea Jun 27 '12 at 10:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.