Nginx 推出支援 HTTP/3 網站伺服器實驗版

Nginx 在昨日發表了 HTTP/3 網站伺服器實驗版 nginx-quic, 設定相當簡單, Nginx 也架設了一個 HTTP/3 測試站, 使用 Chrome Canary 版並啟動 QUIC (Quick UDP Internet Connection) 可以看到通訊協定為 "h3-27", 若你已經在用 Chrome Canary 版且啟動 QUIC, 可以發現 Facebook, Google 等網站都已支援 HTTP/3, 來體驗看看更快速的 Internet!

HTTP各版的差異比較Nginx 推出支援 HTTP/3 網站伺服器實驗版
圖片來自: https://www.nginx.com/blog/introducing-technology-preview-nginx-support-for-quic-http-3/

Nginx HTTP/3 實驗網站: https://quic.nginx.org/
Chrome Canary 版: https://www.google.com/intl/zh-TW/chrome/canary/

由於我使用OS X, 啟動 Chrome Canary 需要加入 --enable-quic --quic-version=h3-27 參數, 例如在終端機輸入
/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --enable-quic --quic-version=h3-27

各種瀏覽器啟動 QUIC 的方法: https://developers.cloudflare.com/http3/intro/

使用 Chrome Canary 瀏覽 Nginx QUIC 測試站
Nginx 推出支援 HTTP/3 網站伺服器實驗版
可以發現觸發"test"頁面時使用的通訊協定是 h3-27 (draft-ietf-quic-http-27)

如果你想實際架設 Nginx QUIC, 這裡下載: https://hg.nginx.org/nginx-quic/shortlog/quic

實際測試


我使用Debian Linux 10為作業系統的虛擬機, 來測試 nginx-quic, 在乾淨的環境下, 會需要一些工具與函式庫來幫助完成 nginx-quic 的編譯與安裝

安裝必要的工具與函式庫
apt-get install psmisc net-tools wget curl build-essential lsb-release cmake golang libunwind-dev git libpcre3-dev zlib1g-dev


下載 BoringSSL 函式庫
git clone https://boringssl.googlesource.com/boringssl
cd boringssl/
mkdir build
cd build/
cmake ..
make


下載 nginx-quic
wget https://hg.nginx.org/nginx-quic/archive/tip.tar.gz
tar zxvf tip.tar.gz
cd nginx-quic-7672ec1e6227
./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"
make
make install


準備憑證與私鑰
cp test.crt /usr/local/nginx/conf
cp test.key /usr/local/nginx/conf


編輯 nginx.conf
nano /usr/local/nginx/conf/nginx.conf


做一個簡單的網站設定
worker_processes  2;

events {
multi_accept on;
use epoll;
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

log_format quic '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$quic" "$http3"';

access_log logs/access.log quic;

sendfile on;
tcp_nopush on;
tcp_nodelay on;

keepalive_timeout 65;

server_tokens off;

server {
listen 80;
server_name _;

location / {
index index.html;
root html;
}
}

server {
listen 443 http3 reuseport;
listen 443 ssl;
server_name quic.example.com;

ssl_certificate test.crt;
ssl_certificate_key test.key;
ssl_protocols TLSv1.3;

location / {
index index.html;
root html;
add_header Alt-Svc '$http3=":443"; ma=86400';

}

}

}

這裡我沒有設定自動轉 HTTPS, 有需要可處理 HTTP 轉 HTTPS

測試設定檔是否正確
/usr/local/nginx/sbin/nginx -t


沒有錯誤就把 nginx-quic 跑起來
/usr/local/nginx/sbin/nginx


接著用 Chrome Canary 瀏覽測試網站
Nginx 推出支援 HTTP/3 網站伺服器實驗版
試了一下有時還是會用HTTP/1.1, reload後又是 HTTP/3
建議待 nginx-quic 釋出正式版本再用於生產環境, 畢竟目前的 nginx-quic 有部分仍未實作, 請見 nginx-quic 的讀我檔案
PC版chrome我已開啟quic嘗鮮
使用起來沒甚麼問題
但是手機板的chrome似乎還沒辦法開啟使用?
PC版可以透過參數強制啟用quic與h3-27, 手機版瀏覽器恐怕沒有門路強制指定使用quic使用h3-27版本
ouchwe wrote:
PC版chrome我(恕刪)
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!