Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1136|回复: 0
打印 上一主题 下一主题

nginx配置gzip压缩

[复制链接]

1228

主题

1996

帖子

7572

积分

认证用户组

Rank: 5Rank: 5

积分
7572
跳转到指定楼层
楼主
发表于 2020-5-13 10:28:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
   #开启gzip压缩
    gzip on;
    #http的协议版本
    gzip_http_version 1.0;
    #IE版本1-6不支持gzip压缩,关闭
    gzip_disable 'MSIE[1-6].';
    #需要压缩的文件格式 text/html默认会压缩,不用添加
    gzip_types text/css text/javascript application/javascript image/jpeg image/png image/gif;
    #设置压缩缓冲区大小,此处设置为4个8K内存作为压缩结果流缓存
    gzip_buffers 4 8k;
    #压缩文件最小大小
    gzip_min_length 1k;
    #压缩级别1-9
    gzip_comp_level 9;
    #给响应头加个vary,告知客户端能否缓存
    gzip_vary on;
    #反向代理时使用
    gzip_proxied off;
———————————————
  1. [root@localhost html]# cat ../conf/nginx.conf

  2. user root;
  3. worker_processes  4;
  4. worker_rlimit_nofile 65535;

  5. events {
  6.     worker_connections  65535;
  7. }


  8. http {
  9.     include       mime.types;
  10.     default_type  application/octet-stream;
  11.     sendfile        on;
  12.     keepalive_timeout  65;

  13.     gzip  on;   #开启gzip
  14.     gzip_min_length 1k; #低于1kb的资源不压缩
  15.     gzip_comp_level 3; #压缩级别【1-9】,越大压缩率越高,同时消耗cpu资源也越多,建议设置在4左右。
  16.     gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;  #需要压缩哪些响应类型的资源,多个空格隔开。不建议压缩图片,下面会讲为什么。
  17.     gzip_disable "MSIE [1-6]\.";  #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
  18.     gzip_vary on;  #是否添加“Vary: Accept-Encoding”响应头

  19.     server {
  20.         listen       80;
  21.         server_name  localhost;
  22.         location / {
  23.             root   html;
  24.             index  index.html index.htm;
  25.         }
  26.         error_page   500 502 503 504  /50x.html;
  27.         location = /50x.html {
  28.             root   html;
  29.         }
  30.     }

  31. }

复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-4-25 07:36 , Processed in 0.053488 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表