HTTP各版的差異比較
圖片來自: 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 測試站
可以發現觸發"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 瀏覽測試網站
試了一下有時還是會用HTTP/1.1, reload後又是 HTTP/3
建議待 nginx-quic 釋出正式版本再用於生產環境, 畢竟目前的 nginx-quic 有部分仍未實作, 請見 nginx-quic 的讀我檔案