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.

In my nginx.conf I have:

gzip              on;
gzip_static       on;
gzip_buffers      16 8k;
gzip_comp_level   9;
gzip_http_version 1.0;
gzip_min_length   1000;
gzip_types        text/plain text/css image/x-icon image/bmp image/png image/gif image/jpeg image/jpg application/json application/x-javascript text/javascript;
gzip_vary         on;
gzip_proxied any;

So, if I fetch the headers of a picture on my server:

spiroo@glamdring:~$ curl -I http://static.mysite.com/g/pics/big_6e1855d844ebca560379139e75942f669655f.jpeg
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 04 Apr 2013 13:00:20 GMT
Content-Type: image/jpeg
Content-Length: 5336
Last-Modified: Mon, 25 Mar 2013 13:28:02 GMT
Expires: Fri, 04 Apr 2014 13:00:20 GMT
Cache-Control: max-age=31536000
Pragma: public
Cache-Control: public, must-revalidate, proxy-revalidate
Accept-Ranges: bytes

But if I turn off the gzip compression in nginx.conf, I have exactly the same result on the Content-Length.

What am I doing wrong?

Thanks in advance.

PS: Just to be clear, I have the nginx last release, and I am behind a proxy (haproxy).

EDIT ==>

I have the same problem with the CSS. I understand jpeg are already compressed. Of crouse, when I switch gzip on/off I restart nginx.

This is my fetch from the headers of a css file. I have the same Content-Lenght with or without gzip compression.

spiroo@glamdring:~$ curl -I http://static.mysite.com/css/9a7f503b.css
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 04 Apr 2013 14:21:50 GMT
Content-Type: text/css
Content-Length: 203088
Last-Modified: Tue, 02 Apr 2013 11:34:39 GMT
Vary: Accept-Encoding
Expires: Fri, 04 Apr 2014 14:21:50 GMT
Cache-Control: max-age=31536000
Pragma: public
Cache-Control: public, must-revalidate, proxy-revalidate
Accept-Ranges: bytes

And this is the nginx configuration for my statics files:

server {
server_name     static.mysite.com;
root /home/www/mysite/current/web;

location / {
    return 404;
}

location ~ \.(?:jpg|jpeg|js|css|gif|png|swf|ico|pdf)$ {
    expires        365d;
    access_log     off;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

}

share|improve this question
add comment

2 Answers

curl doesn't Accept-Encoding: gzip by default. You will need to either use -H "Accept-Encoding: gzip,deflate" to get curl to request gzip or better yet, use --compressed so curl will know to decompress the result.

share|improve this answer
add comment

Pictures (jpg/gif etc) are already compressed. So you don't need to (and shouldn't try to) compress them on the web server.

Here is an example of what I compress:

gzip_types        text/html text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;
share|improve this answer
    
Thanks for your comments. But I have the same problem with CSS if I turn on the gzip compression or if I turn off the gzip compression, the Content-Length is the same. –  Jerry Apr 4 '13 at 13:25
    
Can you update your question with a more sensible confugration and relevant headers then? (BTW did you restart the server to make sure the changes were applied) –  symcbean Apr 4 '13 at 13:31
    
You will need to reload or restart nginx so that it will see the new config (as symcbean said). –  Drew Khoury Apr 4 '13 at 13:35
    
Question updated. –  Jerry Apr 4 '13 at 14:25
    
Have you tried in a browser, like Chrome ... instead of just curl? –  Drew Khoury Apr 4 '13 at 14:38
add comment

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.