2

I'm trying to figure out why my custom CDN on nginx, doesn't appear to be working. Here is what I have in my site configuration:

server {

    listen   80;
    listen [::]:80;

    server_name cdn.site.co.uk;

    root /srv/www/site.co.uk/bob_user;

    if ($uri !~ "\.(gif|jpe?g|png|js|css|eot|woff|ttf|svg)$") {
        rewrite ^/(.*)$ https://site.co.uk/ permanent;
    }

    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

}

The file itself works - but using this tool, it tells me that it does:

https://varvy.com/tools/gzip/

enter image description here

This is the URL I tested:

http://cdn.businessofbrands.co.uk/wp-includes/js/jquery/jquery.js

I'm a bit confused as to why this is. Could anyone shed some light?

Andrew Newby
  • 4,941
  • 6
  • 40
  • 81
  • I believe this may be because you're missing `application/javascript` from `gzip_types` (which is the content-type used for `jquery.js`) – Sean3z Feb 03 '16 at 13:50
  • @Sean3z - ah man, not sure how I missed that! Works like a charm now :) Please add that as an answer, and I'll accept as soon as it lets me. Thanks! – Andrew Newby Feb 03 '16 at 13:52

1 Answers1

3

It looks like application/javascript is missing from gzip_types.

You'll want to add it to the following line:

gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;

Actually, text/javascript is obsolete so you could just replace it :)

Sean3z
  • 3,745
  • 6
  • 26
  • 33