前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >utuntu22.04安装含brotli模块的Ningx

utuntu22.04安装含brotli模块的Ningx

作者头像
typecodes
发布2024-03-29 15:20:42
750
发布2024-03-29 15:20:42
举报
文章被收录于专栏:typecodestypecodes
一、更新源:

代码语言:javascript
复制
cp /etc/apt/sources.list /etc/apt/sources.list.bak

### 替换成阿里云的源
sudo bash -c "cat << EOF > /etc/apt/sources.list && apt update 
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
EOF"

### 重启
reboot

### 更新
apt update -y && apt upgrade && apt install dpkg-dev
二、开始安装 nginx 和 brotli
代码语言:javascript
复制
### 安装nginx
apt install nginx
systemctl enable nginx.service

### 编译brotli
apt source nginx && apt build-dep nginx
git clone --recursive https://github.com/google/ngx_brotli.git
cd nginx-1.18.0 && ./configure --with-compat --add-dynamic-module=../ngx_brotli && make modules

### 库文件
cp ./objs/*.so /usr/share/nginx/modules
vim /usr/share/nginx/modules-available/mod-http-brotli.conf
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;

cd /etc/nginx/modules-enabled && ln -s /usr/share/nginx/modules-available/mod-http-brotli.conf 50-mod-http-brotli.conf

### brolit 配置文件
vim /etc/nginx/conf.d/brotli.conf
# Enable Brotli
brotli            on;
brotli_static     on;
brotli_comp_level 6;

# File types to compress
brotli_types application/atom+xml application/javascript application/json application/rss+xml
             application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype
             application/x-font-ttf application/x-javascript application/xhtml+xml application/xml
             font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon
             image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;
三、验证
代码语言:javascript
复制
### 重启nginx
systemctl restart nginx

### 验证,出现 content-encoding: br 表示生效
root@VM-0-12-ubuntu:~# curl -H 'Accept-Encoding: br' -I https://typecodes.com
HTTP/2 200 
server: nginx
date: Wed, 03 May 2023 16:21:44 GMT
content-type: text/html; charset=utf-8
last-modified: Fri, 03 Mar 2023 09:25:39 GMT
vary: Accept-Encoding
etag: W/"6401bd13-412d"
strict-transport-security: max-age=31536000; includeSubdomains;preload
x-frame-options: DENY
x-content-type-options: nosniff
public-key-pins: pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; pin-sha256="aef6IF2UF6jNEwA2pNmP7kpgT6NFSdt7Tqf5HzaIGWI="; max-age=2592000; includeSubDomains
cache-control: no-cache
content-security-policy: default-src disqus.com disquscdn.com; script-src 'unsafe-inline' 'unsafe-eval' blob: https:; img-src 'self' https: hm.baidu.com disqus.com; style-src 'unsafe-inline' https:; child-src https:; connect-src 'self' https: hm.baidu.com disqus.com; frame-src https://disqus.com
content-encoding: br

root@VM-0-12-ubuntu:~# 
response 出现 br 则表示已经启用 br 压缩
response 出现 br 则表示已经启用 br 压缩
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-05-29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、更新源:
  • 二、开始安装 nginx 和 brotli
  • 三、验证
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档