【问题标题】:How can I enable gzip text compression in universal angular and nginx?如何在通用 Angular 和 nginx 中启用 gzip 文本压缩?
【发布时间】:2019-10-09 14:41:26
【问题描述】:

有谁知道如何在 nginx 和通用 Angular 中启用 gzip 文本压缩?我不知道从哪里开始做它

【问题讨论】:

    标签: angular nginx gzip angular-universal


    【解决方案1】:

    gzip 与 Angular 无关,它是服务器的东西。 在nginx中你可以通过设置gzip on;来启用它

    如下:

    server {
        gzip on;
        gzip_types      text/plain application/xml;
        gzip_proxied    no-cache no-store private expired auth;
        gzip_min_length 1000;
        ...
    }
    

    详情请看以下文章:

    https://docs.nginx.com/nginx/admin-guide/web-server/compression/

    【讨论】:

    • 非常感谢您的问候
    【解决方案2】:

    第一步是编辑 nginx.conf 文件,在大多数发行版中,该文件可能位于 /etc/nginx/nginx.conf/usr/local/nginx/conf/nginx.conf

    使用您喜欢的编辑器打开 nginx.conf 文件。您可以看到已经有一个关于 Gzip 的设置块;您可以随时修改这些内容并取消注释,如下所示:

    # enable gzip compression
    
    # Turns on/off the gzip compression.
    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    5;
    
    # The minimum size file to compress the files.
    gzip_min_length  1100;
    
    # Set the buffer size of gzip, 4 32k is good enough for almost everybody.
    gzip_buffers  4 32k;
    
    # Compress data even for clients that are connecting to us via proxies,
    # identified by the "Via" header (required for CloudFront).
    gzip_proxied       any;
    
    # This directive let you specify which file types should be compressed, in this case plain text, js files, xml and #css.
    gzip_types    text/plain application/x-javascript text/xml text/css;
    
    # Enables response header of “Vary: Accept-Encoding
    gzip_vary on;
    
    # end gzip configuration
    

    完成上述配置更改后,重新启动或重新加载您的服务器,您现在将使用 gzip 压缩来提供站点资产。

    /etc/init.d/nginx reload
    

    sudo service nginx restart
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-31
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      • 2019-07-03
      • 2013-12-29
      • 1970-01-01
      相关资源
      最近更新 更多