utuntu22.04安装含brotli模块的Ningx
一、更新源:
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
### 安装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;
三、验证
### 重启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:~#
打赏支持
Comments »