nginx gzip压缩似乎不起作用

时间:2016-02-03 13:10:32

标签: nginx gzip

我正在试图找出为什么我在nginx上的自定义CDN似乎没有起作用。以下是我在网站配置中的内容:

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;

}

文件本身有效 - 但是使用这个工具,它告诉我它确实:

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

enter image description here

这是我测试过的网址:

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

我有点困惑为什么会这样。任何人都可以解释一下吗?

1 个答案:

答案 0 :(得分:3)

application/javascript似乎缺少gzip_types

您需要将其添加到以下行:

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

实际上,text/javascriptobsolete所以您可以替换它:)