• 欢迎访问db1024网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏db1024吧

宝塔面板LNMP开启Brotli压缩,可提高网站加载速度

建站知识 Liam 1年前 (2019-06-14) 594次浏览 10个评论 扫描二维码
文章目录[隐藏]

说明:BrotliGoogle推出的开源压缩算法,通过变种的LZ77算法、Huffman编码以及二阶文本建模等方式进行数据压缩,与其他压缩算法相比,它有着更高的压缩效率,性能也比我们目前常见的Gzip17-25%,可以帮我们更高效的压缩网页中的各类文件大小及脚本,从而提高加载速度,提升网页浏览体验。博主目前也给开启了Brotli压缩,体验还行吧,这里就说下宝塔面板的开启方法。

安装

1、下载Brotli

cd /www/server #下载brotli git clone https://github.com/google/ngx_brotli.git cd ngx_brotli #更新brotli git submodule update --init 

2、编译Nginx
先查看目前的Nginx版本信息,使用命令:

nginx -V

大概会输出以下信息:

[[email protected] ~]# nginx -V nginx version: nginx/1.15.10 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)  built with OpenSSL 1.1.1b  26 Feb 2019 TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/www/server/nginx --with-openssl=/www/server/nginx/src/openssl ... --with-ld-opt=-ljemalloc 

nginx版本为1.15.10configure arguments:后面的为你nginx的编译参数,下面会用到。

然后重新下载nginx,并开始编译,使用命令:

#下载nginx,这里下载的1.15.10版本,如果是其它版本,把下载链接的1.15.10改成你的版本号即可 wget http://nginx.org/download/nginx-1.15.10.tar.gz #解压并删除压缩包 tar -xvzf nginx-*.tar.gz && rm -rf nginx-*.tar.gz #进入nginx目录 cd nginx* #生成Makefile,./configure后面的参数直接复制上面看到的,然后在后面额外加一个--add-module=/www/server/ngx_brotli ./configure --user=www --group=www --prefix=/www/server/nginx ... --add-module=/www/server/ngx_brotli #编译nginx make && make install 

不出意外的话,就编译完成了,然后继续使用命令查看信息:

nginx -V

返回参数后面多了个--add-module=/www/server/ngx_brotli就编译成功了。
宝塔面板LNMP开启Brotli压缩,可提高网站加载速度

3、开启Brotli压缩
接下来点击面板左侧软件商店-Nginx设置-配置修改,在http段内添加以下内容来启用Brotli压缩。

brotli on; brotli_comp_level 6; brotli_min_length 512; brotli_types text/plain text/javascript text/css text/xml text/x-component application/javascript application/x-javascript application/xml application/json application/xhtml+xml application/rss+xml application/atom+xml application/x-font-ttf application/vnd.ms-fontobject image/svg+xml image/x-icon font/opentype; brotli_static always;

最后点击Nginx设置里的重载配置生效即可。

Brotli全部参数详解:

brotli on;              #启用 brotli_comp_level 6;    #压缩等级,默认6,最高11,太高的压缩水平可能需要更多的CPU brotli_buffers 16 8k;   #请求缓冲区的数量和大小 brotli_min_length 20;   #指定压缩数据的最小长度,只有大于或等于最小长度才会对其压缩。这里指定20字节 brotli_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml text/html application/json image/svg application/font-woff application/vnd.ms-fontobject application/vnd.apple.mpegurl image/x-icon image/jpeg image/gif image/png image/bmp;   #指定允许进行压缩类型 brotli_static always;   #是否允许查找预处理好的、以.br结尾的压缩文件,可选值为on、off、always brotli_window 512k;     #窗口值,默认值为512k 

全部配置好了,就可以使用谷歌浏览器查看下是否开启成功,看到br字段即为成功。
宝塔面板LNMP开启Brotli压缩,可提高网站加载速度
最后博主感觉压缩效果还行,有兴趣的可以开一下,对于其它的安装环境,安装方法都差不多,这里默认是BrotliGzip共存,并且都启用了,好处就是部分老旧的浏览器不支持Brotli的时候会自动变成Gzip压缩。


db1024 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:宝塔面板LNMP开启Brotli压缩,可提高网站加载速度
喜欢 (3)
关于作者:
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(10)个小伙伴在吐槽
  1. Hello Dear, are you genuinely visiting this website regularly, if so afterward you will without doubt get good knowledge.
    black mass2020-08-31 08:41 回复 Mac OS X | Chrome 67.0.3396.79
  2. Hey There. I found your weblog the use of msn. That is a really smartly written article. I will make sure to bookmark it and return to read more of your helpful info. Thanks for the post. I'll certainly comeback.
    black mass2020-08-28 21:09 回复 Mac OS X | Chrome 67.0.3396.79
  3. Whats up this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I'm starting a blog soon but have no coding experience so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!
    cheap flights2020-08-28 07:41 回复 Mac OS X | Firefox浏览器 61.0
  4. Hello, i think that i saw you visited my weblog so i came to “return the favor”.I am attempting to find things to improve my web site!I suppose its ok to use a few of your ideas!!
    cheap flights2020-08-27 10:44 回复 Mac OS X | Chrome 65.0.3325.181
  5. Hey! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us beneficial information to work on. You have done a wonderful job!
    cheap flights2020-08-26 17:05 回复 Linux | Safari浏览器 605.1.15
  6. Hi there I am so glad I found your blog, I really found you by mistake, while I was searching on Google for something else, Anyhow I am here now and would just like to say thanks a lot for a remarkable post and a all round enjoyable blog (I also love the theme/design), I don't have time to go through it all at the minute but I have book-marked it and also added in your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the awesome job. cheap flights 3gqLYTc
    cheap flights2020-08-25 22:30 回复 Windows 7 | Internet Explorer 9.0
  7. Excellent way of describing, and fastidious piece of writing to obtain facts concerning my presentation topic, which i am going to present in college. y2yxvvfw cheap flights
    cheap flights2020-08-25 03:43 回复 Windows 8.1 | Firefox浏览器 60.0
  8. Your means of describing the whole thing in this article is really nice, all be capable of simply be aware of it, Thanks a lot.
    cheap flights2020-08-24 16:11 回复 Linux | Safari浏览器 605.1.15
  9. Right now it seems like Expression Engine is the top blogging platform out there right now. (from what I've read) Is that what you are using on your blog?
    web hosting service2020-08-14 21:20 回复 Linux | Chrome 65.0.3325.181
  10. I am really thankful to the holder of this website who has shared this fantastic piece of writing at here.
    best website hosting2020-08-11 02:27 回复 Linux | Chrome 65.0.3325.181