安装并使用nginx-quic
① 安装boringssl
https://github.com/google/boringssl
通过xftp上传到nginx所在主机的/usr/local/目录下。
unzip boringssl-master.zip -d /usr/local/
mv boringssl-master boringssl
mkdir build
cd build
apt install gcc
apt install g++
cmake …
make
② 安装nginx-quic
https://hg.nginx.org/nginx-quic
通过xftp上传到nginx所在主机的/usr/local/目录下。
unzip nginx-quic.zip -d /usr/local/
mv nginx-quic-9ea62b6250f2 nginx
cd nginx
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
./auto/configure --with-debug --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”
make && make install
cd /usr/local/nginx
mkdir logs
cd logs
touch access.log error.log
为了更方便的使用nginx,将可执行文件加入环境变量:
vim /etc/profile
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
source /etc/profile
③ 申请域名并下载SSL证书
3.1 在腾讯云申请域名,并解析到nginx所在主机的IP。
3.2 为域名签发证书。
3.3 签发成功后,下载证书
需要key和pem这两个文件。
将.key文件和.pem文件放在/usr/local/nginx/conf/certs目录下。
④ 修改nginx.conf配置文件
events {
worker_connections 1024;
}
http {
log_format quic '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" ';
access_log logs/access.log quic;
server {
# for better compatibility it's recommended
# to use the same port for quic and https
listen 8443 quic reuseport;
listen 8443 ssl;
ssl_certificate certs/www.cantina.top_bundle.pem;
ssl_certificate_key certs/www.cantina.top.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
location / {
# required for browsers to direct them into quic port
add_header Alt-Svc 'h3=":8443"; ma=86400';
}
}
}
⑤ 测试nginx.conf,启动nginx
nginx -t
nginx
ps -ef | grep nginx
浏览器默认不支持http3,需要修改配置后重启。
Google Chrome
在浏览器地址栏输入并回车:chrome://flags/#enable-quic
将 Experimental QUIC protocol 设置为 Enabled
Mozilla Firefox
在浏览器地址栏输入并回车:about:config
将 network.http.http3.enabled 设置为 true
Microsoft Edge
在浏览器地址栏输入并回车:edge://flags/#enable-quic
将 Experimental QUIC protocol 设置为 Enabled
通过浏览器访问https://www.cantina.top:8443进行测试。
查看access.log: