javascript - nginx 开启gzip 不生效

查看:408
本文介绍了javascript - nginx 开启gzip 不生效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

我这段代码跟server平级
只有html文件有

js css 都没生效


请问什么原因
我是这么配置的

解决方案

以下是我的配置,之前我碰到的问题是safari无效了,加了gzip_static on;才行

    # Enable Gzip compressed.
    # http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_http_version
    gzip on;

    # Compression level (1-9).
    #5 is a perfect compromise between size and cpu usage, offering about
    #75% reduction for most ascii files (almost identical to level 9).
    gzip_comp_level    9;

    # Don't compress anything that's already small and unlikely to shrink much
    # if at all (the default is 20 bytes, which is bad as that usually leads to
    # larger files after gzipping).
    gzip_min_length    256;
    gzip_disable "msie6";

    gzip_buffers 32 4k;
    gzip_http_version 1.1;
    # https://www.mail-archive.com/search?l=nginx@nginx.org&q=subject:%22Gzip+issue+with+Safari%22&o=newest&f=1  for safira
    gzip_static on;

    # Compress data even for clients that are connecting to us via proxies,
    # identified by the "Via" header (required for CloudFront).
    gzip_proxied       any;

    # Tell proxies to cache both the gzipped and regular version of a resource
    # whenever the client's Accept-Encoding capabilities header varies;
    # Avoids the issue where a non-gzip capable client (which is extremely rare
    # today) would display gibberish if their proxy gave them the gzipped version.
    gzip_vary          on;

    # Compress all output labeled with one of the following MIME-types.
    gzip_types
        application/atom+xml
        # 这个application/x-javascript还是有区别的
        application/javascript
        application/json
        application/ld+json
        application/manifest+json
        application/rss+xml
        application/vnd.geo+json
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/bmp
        image/svg+xml
        image/x-icon
        text/cache-manifest
        text/css
        text/plain
        text/vcard
        text/vnd.rim.location.xloc
        text/vtt
        text/x-component
        application/octet-stream
        text/x-cross-domain-policy;
    # text/html is always compressed by HttpGzipModule

这篇关于javascript - nginx 开启gzip 不生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆