
重新编译nginx,以便支持最新的quic(http3)以及 brotli 压缩
重新编译nginx,以便支持最新的quic(http3)以及 brotli 压缩
目前nginx的管网主线版本以及包含了quic(http3)支持了,直接在线安装即可。。。
下面是安装nginx主线版本的方法,就不翻译了,大致上接触过Linux系统的应该看得懂
Install the prerequisites:
Debian
Install the prerequisites:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
Import an official nginx signing key so apt could verify the packages authenticity. Fetch the key:
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
Verify that the downloaded file contains the proper key:
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
The output should contain the full fingerprint 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 as follows:
pub rsa2048 2011-08-19 [SC] [expires: 2027-05-24]
573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid nginx signing key <[email protected]>
Note that the output can contain other keys used to sign the packages.
To set up the apt repository for stable nginx packages, run the following command:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
If you would like to use mainline nginx packages, run the following command instead:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
Set up repository pinning to prefer our packages over distribution-provided ones:
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
| sudo tee /etc/apt/preferences.d/99nginx
To install nginx, run the following commands:
sudo apt update
sudo apt install nginx
参考: https://nginx.org/en/linux_packages.html
nginx 安装好了,但是不支持brotli 压缩,所以需要重新编译一遍nginx
编译安装nginx的必要环境
1
2
apt update
apt install build-essential ca-certificates zlib1g-dev libpcre3 libpcre3-dev tar unzip libssl-dev wget curl git cmake ninja-build mercurial libunwind-dev pkg-config gcc g++
支持brotli 压缩
1
2
3
4
git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli
git submodule update --init
cd ..
下载nginx源代码,进入nginx源代码根目录,执行以下代码编译nginx,下面的编译参数实在虚拟机上Debian系统示例
请根据实际情况修改,执行nginx -V即可查看已安装nginx编译的参数
1
2
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/dev/shm/nginx.pid --lock-path=/dev/shm/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=www-data --group=www-data --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_v3_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=/root/nginx/ngx_brotli --with-cc-opt='-g -O2 -ffile-prefix-map=/data/builder/debuild/nginx-1.25.1/debian/debuild-base/nginx-1.25.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'
重点,重点,重点
执行make,而不是make install否则会覆盖系统已经安装的nginx包括参数等等。
执行make,没有报错的nginx就编译好了,保存在nginx根目录下的objs目录下
把objs目录下nginx替换到实际运行的nginx目录即可,
执行nginx -v如果出现下面代码即可
1
--add-module=/root/nginx/ngx_brotli
添加brotli 压缩代码,重载nginx没有报错即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
text/javascript application/javascript application/x-javascript
text/x-json application/json application/x-web-app-manifest+json
text/css text/plain text/x-component
font/opentype application/x-font-ttf application/vnd.ms-fontobject
image/x-icon;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
##Brotli Compression
brotli on;
brotli_comp_level 6;
brotli_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;
💘 相关文章
- nginx 开启http3 QUIC和配置Brotli压缩和反向代理的详细教程
- nginx打上QUIC补丁,抢先体验http3
- 在ARM服务器中基于ubuntu系统一键架设nginx quic http3环境
- nginx 使用gzip和Brotli压缩对比测试
- 快速简单一键搭建nginx quic的环境
- nginx: [emerg] unknown directive "set_real_ip_from"的解决方法
- 解决nginx反向代理验证码不显示的方法
- nginx: [warn] "ssl_stapling" ignored, not supported告警
- nginx nginx "--with-ipv6" option is deprecated 问题
- nginx "ssl_stapling" ignored, issuer certificate not found for certificate解决方法