QUIC实战(五) 使用nginx quic开发分支部署支持HTTP3 的NGINX
使用nginx + Quiche 部署的支持HTTP3的nginx在實(shí)際測(cè)試過(guò)程中遇到了一些問(wèn)題,Quiche本身是由go + rust編寫(xiě)的,nginx又是由c++編寫(xiě)的,對(duì)于我們來(lái)說(shuō)未知的內(nèi)容太多,所以嘗試使用nginx的quic開(kāi)發(fā)分支來(lái)部署一個(gè)支持HTTP3的nginx服務(wù)器。
1.下載并安裝boringssl
yum install git git clone https://boringssl.googlesource.com/boringssl編譯boringssl需要cmake和go,而 cmake 的編譯安裝需要gcc和openssl,所以先安裝依賴(lài)環(huán)境
yum install go yum install wget wget https://cmake.org/files/v3.16/cmake-3.16.0-rc2.tar.gz tar xvzf cmake-3.16.0-rc2.tar.gz ## 安裝編譯依賴(lài)--- 這里安裝了gcc, openssl yum install -y gcc-c++ make automake openssl-devel ## 開(kāi)始編譯 cd cmake-3.10.0-rc2/ ./bootstrap --prefix=/usr --datadir=share/cmake --docdir=doc/cmake && make sudo make install
2. 編譯 boringssl
cd boringsslmkdir buildcd buildcmake ..make
3. 安裝nginx-quic
注意: hg命令是程序mercurial程序的執(zhí)行命令,所以我們需要安裝的是mercurial,而不是hg
$ yum install mercurial $ hg clone -b quic https://hg.nginx.org/nginx-quic $ cd nginx-quic $ ./auto/configure \--prefix=/opt/server/nginx \--with-debug --with-http_v3_module \--with-http_ssl_module \--with-http_v2_module \--with-stream_quic_module \--with-cc-opt="-I../boringssl/include" \--with-ld-opt="-L../boringssl/build/ssl \-L../boringssl/build/crypto" \--add-module=../nginx-upsync-module-master $ make ## 安裝 $ sudo make install–with-http_v3_module - enable QUIC and HTTP/3
–with-http_quic_module - enable QUIC for older HTTP versions
–with-stream_quic_module - enable QUIC in Stream
發(fā)生如下報(bào)錯(cuò):
提示需要安裝pcre,步驟如下:
安裝完成后啟動(dòng)nginx,發(fā)生如下報(bào)錯(cuò):
sbin/nginx: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
解決辦法: 進(jìn)入到lib64目錄下,執(zhí)行 ln -n libpcre.so.1.2.10 /lib64/libpcre.so.0 具體的libpcre.so的版本號(hào)看你本機(jī)安裝的是什么版本
接下來(lái)還需要安裝證書(shū),步驟參考:
QUIC實(shí)戰(zhàn)(三) letsencrypt證書(shū)申請(qǐng)和自動(dòng)續(xù)期 就不贅述了。
最后,nginx的配置文件如下:
#user nobody; worker_processes 1;#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;#pid logs/nginx.pid; events {worker_connections 1024; }http {include mime.types;default_type application/octet-stream;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$ssl_protocol/$ssl_cipher ''$status $body_bytes_sent $bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for" ''$request_time $upstream_response_time';access_log logs/access.log main;#error log level debugerror_log logs/error.log debug;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}include /opt/server/nginx/conf/conf.d/*.conf; }h3server.conf
# upstream config upstream myserver {server 127.0.0.1:11111;#超時(shí)是6m 間隔是500mupsync 172.xx.xx.xx:8500/v1/kv/upstreams/ibu-quic upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;upsync 172.xx.xx.xx:8500/v1/kv/upstreams/ibu-quic upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;upsync 172.xx.xx.xx:8500/v1/kv/upstreams/ibu-quic upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;#從consul拉取的上游服務(wù)器后持久化的位置upsync_dump_path /opt/data/consul/server.conf; }server {# Enable QUIC and HTTP/3.listen 443 http3 reuseport;# Enable HTTP/2 (optional).listen 443 ssl http2;ssl_certificate /etc/letsencrypt/live/xx/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/xx/privkey.pem;quic_retry on;ssl_early_data on;# Enable all TLS versions (TLSv1.3 is required for QUIC).ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;location /quic {add_header Alt-Svc 'h3-29=":443"; ma=86400';proxy_pass http://myserver;} }nginx的配置和之前使用Quiche搭建的支持HTTP3的nginx的配置差不多,就是加了關(guān)于nginx 日志格式和error日志的配置,值得注意的是:如果在編譯nginx的時(shí)候沒(méi)有加--with-debug這一參數(shù),那么哪怕在nginx.conf里配置了debug級(jí)別的error日志,最后輸出的還是不含debug信息的。
測(cè)試了下新的支持HTTP3的nginx服務(wù),測(cè)試結(jié)果比之前Quiche的好很多。
PS: debug的error日志級(jí)別并不建議在流量大的時(shí)候使用,因?yàn)榇罅康恼?qǐng)求會(huì)導(dǎo)致error.log把整個(gè)磁盤(pán)空間占滿(mǎn)!
參考資料:
Experimental QUIC support for nginx
總結(jié)
以上是生活随笔為你收集整理的QUIC实战(五) 使用nginx quic开发分支部署支持HTTP3 的NGINX的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux常用安装命令集锦
- 下一篇: nginx如何开启debug日志及相关配