首页 > 其他 > 详细

Nginx 配置 Gzip 压缩

时间:2019-02-24 16:16:58      阅读:216      评论:0      收藏:0      [点我收藏+]

打开配置文件 /etc/nginx/nginx.conf,取消掉以下的注释项:

#gzip on;

取消后:

gzip on;

在此配置后加上以下内容:

gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

以上各项的详解:

  • gzip on; - 启用gzip压缩;
  • gzip_vary on; - 告知代理缓存常规及压缩版本;
  • gzip_min_length 1024; - 告知 NGINX 不压缩小于指定大小的内容;
  • gzip_proxied - 即使客户端是通过代理连接也压缩文件 (此处配置为:当一个response头部包含"expired"、"no-cache"、 "no-store"、"private"或"Authorization"时启用压缩);
  • gzip_types - 能够被压缩的文件类型;
  • gzip_disable "MSIE [1-6]\."; - Internet Explorer 1-6 的版本禁用压缩。

修改完成后可以使用 nginx -t 测试修改的配置文章,确定无误后重启nginx服务即可,重启命令:

systemctl restart nginx

或者:

nginx -s reload

参考:https://www.techrepublic.com/article/how-to-configure-gzip-compression-with-nginx/

Nginx 配置 Gzip 压缩

原文:https://www.cnblogs.com/gebilaowangpython/p/10426492.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!