logo 🤗

技术视野

聚焦科技前沿,分享技术解析,洞见未来趋势。在这里,与您一起探索人工智能的无限可能,共赴技术盛宴。

sudo apt install -y mercurial libperl-dev libpcre3-dev zlib1g-dev libxslt1-dev libgd-ocaml-dev libgeoip-dev
  • 编译nginx参数
./configure \
--with-http_v2_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_image_filter_module \
--with-http_gzip_static_module \
--with-http_gunzip_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_addition_module \
--with-http_realip_module \
--with-http_mp4_module \
--with-ld-opt=-Wl,-E \
--with-cc-opt=-Wno-error

遇到的问题

提示 没有安装GD library:
./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.

解决:

sudo apt-get install -y libgd-dev

如果在安装libgd-dev时提示找不到
在 vim /etc/apt/sources.list 中添加一行ubuntu 的镜像源
deb http://security.ubuntu.com/ubuntu trusty-security main

提示 没有 GeoIp library
./configure: error: the GeoIP module requires the GeoIP library.
You can either do not enable the module or install the library.

解决

sudo apt-get install libgeoip-dev
 warning: the "--with-ipv6" option is deprecated

安装http3模块

  1. 安装包
sudo apt-get install mercurial
hg clone -b quic https://hg.nginx.org/nginx-quic
cd nginx-quic

# 切换到v1.2.2,与nginx一致
hg branch v1.2.2
  1. 配置(推荐)
./auto/configure \
--prefix=/usr/local/nginx \
--with-http_v2_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_image_filter_module \
--with-http_gzip_static_module \
--with-http_gunzip_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_addition_module \
--with-http_realip_module \
--with-http_mp4_module \
--with-http_v3_module \
--with-stream_quic_module \
--with-cc-opt=-I../boringssl/include \
--with-ld-opt='-L../boringssl/build/ssl -L../boringssl/build/crypto'

编译配置2

cd nginx-quic
./auto/configure \
--with-debug \
--with-http_v3_module \
--with-cc-opt="-I../boringssl/include" \
--with-ld-opt="-L../boringssl/build/ssl -L../boringssl/build/crypto" \
--with-openssl-opt='enable-tls1_3' \
--with-http_v2_module \
--with-http_ssl_module\
--with-http_gzip_static_module \
--with-stream_quic_module
make
make install

nginx开机自启

  1. 检查nginx配置
sudo /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
  1. 修改nginx.service
sudo vim /lib/systemd/system/nginx.service

利用vim替换

:%s/usr/usr\/local\/nginx/g
:%s/run\/nginx.pid/usr\/local\/nginx\/logs\/nginx.pid

修改结果如下:

[Unit]                                                                          
Description=A high performance web server and a reverse proxy server            
Documentation=man:nginx(8)                                                      
After=network.target nss-lookup.target                                          
                                                                                
[Service]                                                                       
Type=forking                                                                    
PIDFile=/usr/local/nginx/logs/nginx.pid                                         
ExecStartPre=/usr/local/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;'        
ExecReload=/usr/local/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /usr/local/nginx/logs/nginx.pid
TimeoutStopSec=5                                                                
KillMode=mixed                                                                  
                                                                                
[Install]                                                                       
WantedBy=multi-user.target
  1. 重启nginx
sudo systemctl daemon-reload
sudo systemctl restart nginx.service

迁移配置文件(可选)

  1. 创建vhost文件夹,用于迁移虚拟主机
sudo makedir /usr/local/nginx/vhost
  1. 编辑conf文件
sudo vim /usr/local/nginx/conf/nginx.conf

在http下面新增

include /usr/local/nginx/vhost/*.conf;

迁移文件 vhost目录下的文件

sudo cp /etc/nginx/vhost/*.conf /usr/local/nginx/vhost/

迁移证书目录

sudo mkdir /usr/local/nginx/cert
sudo cp -r /etc/nginx/vhost/cert/* /usr/local/nginx/cert

浏览器开启http3

chrome://flags
搜索quic,默认是default,也是开启
  • 浏览器打开f12,然后右键,增加协议,可以看到h3样式。
    image.png

版权属于:tlntin
作品采用:本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
更新于: 2023年05月26日 14:31


39 文章数
5 分类数
40 页面数
已在风雨中度过 1年160天14小时30分
目录
来自 《nginx编译http v3》
暗黑模式
暗黑模式
返回顶部
暗黑模式
暗黑模式
返回顶部