3

Some files are not gzipped on their way to the user browser in our setup.

for example

http://myhostname.com/css/build/20120904-1.css

http://myhostname.com/js/dojo/dn/main.js?20120904-1

http://myhostname.com/js/jquery-min/compiled.js?20120725-4

can not be zipped.

my current configuration:

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)\.*+$ {
            if ($args ~ [0-9]\.*+) {
               expires max;
               break;
            }
            expires max;
            log_not_found off;
             gzip  on;
    }

What needs to be adjusted to make gzip fly? I already tried several other options but don't want to continue with try&error on this.

Thank you very much.

Some more info: maybe there is another problem. Firebug and pingdom tools show me the compressed size whereas Chrome Developer Bar and Google PageSpeed Insights says "no compression active"

To make things easier, the link to the site is http://diginights.com

shakalandy
  • 768
  • 4
  • 10

3 Answers3

6

You need to set gzip_types application/x-javascript text/css; By default, nginx will only gzip text/html.

kolbyjack
  • 7,854
  • 2
  • 34
  • 29
  • gzip_types is set. To make things clearer i edited some more infos in the question, and the link to the real site. – shakalandy Sep 17 '12 at 13:16
3
location ~* \.(js|css|png|jpg|jpeg|gif|ico)\.*+$ {

This regular expression doesn't match your example requests at all.

The right one:

location ~* \.(?:js|css|png|jpe?g|gif|ico)$ {
VBart
  • 8,159
  • 3
  • 24
  • 25
  • it seems as if it's working, at least for firebug. but not in chrome developer toolbar or google pageinsights online. I edited some more info at the top. – shakalandy Sep 17 '12 at 13:16
  • Chrome and pageinsights just cached your previous result. – VBart Sep 17 '12 at 14:53
2

That's because your configuration seems to be telling it not to do so for any file with a digit 0-9 in the name.

Delete this entire section; it's mostly redundant anyway, and almost certainly isn't doing anything that you might want.

        if ($args ~ [0-9]\.*+) {
           expires max;
           break;
        }
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • thanks for your answer. I should have been more clear on this. Of course i tried it without this if section, but somehow nginx won't recognize the files as css/js files when a timestamp is used in the query string. Deleting this section has no effect, the files aren't zipped either. – shakalandy Sep 16 '12 at 10:40
  • While the if is unnecessary, it would not prevent nginx from gzipping responses, as the gzip setting would be inherited by the if-location. For gzip to be disabled inside the if, it would need to explicitly be set (and I'm not sure if that's possible). – kolbyjack Sep 16 '12 at 17:53
  • Nginx doesn't care about "query string". Your problem is somewhere else, and you should delete this `if` section anyway. – VBart Sep 17 '12 at 02:18