Nginx 开启 Gzip 压缩

最近更新于 2024-05-05 12:29

基于 Nginx 1.18
Nginx 默认配置文件 /etc/nginx/nginx.conf

开启 Gzip 会压缩传输的资源,减小带宽需求,提高加载速度。

在 http {} 中添加
(配置文件中默认是有一段 Gzip Settings,解开注释即可)

    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_min_length 256;
    gzip_http_version 1.1;

    gzip_types text/plain text/css text/x-component text/html application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/x-icon image/svg+xml image/jpeg image/gif image/png font/opentype;

重启服务器

sudo service nginx restart
Nginx 开启 Gzip 压缩
Scroll to top