5

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"; } 

}

2 Answers 2

5

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.

1
  • for debugging purposes use the verbose output of curl -v as this will also show you all request headers and not just the response. Commented Mar 4, 2016 at 14:54
4

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; 
6
  • 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. Commented Apr 4, 2013 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) Commented Apr 4, 2013 at 13:31
  • You will need to reload or restart nginx so that it will see the new config (as symcbean said). Commented Apr 4, 2013 at 13:35
  • Question updated. Commented Apr 4, 2013 at 14:25
  • Have you tried in a browser, like Chrome ... instead of just curl? Commented Apr 4, 2013 at 14:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.