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模块
- 安装包
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
- 配置(推荐)
./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开机自启
- 检查nginx配置
sudo /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
- 修改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
- 重启nginx
sudo systemctl daemon-reload
sudo systemctl restart nginx.service
迁移配置文件(可选)
- 创建vhost文件夹,用于迁移虚拟主机
sudo makedir /usr/local/nginx/vhost
- 编辑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样式。