初次使用nginx 搭建http2.0
源碼的下載地址
目前1.9.5已經加入http2.0的支持,
編譯參數
./configure --prefix=/usr/local/nginx --with-openssl=/opt/openssl-1.0.2e --with-pcre --with-zlib=/opt/zlib-1.2.8 --with-stream --with-stream_ssl_module --with-http_ssl_module --with-http_v2_module --with-threads
這里需要自行下載openssl、zlib源碼包,其中openssl需要注意,需要1.0.2以上版本需要對tls支持,否則會報錯開啟http2的時候。
推薦使用這個版本
wget http://www.openssl.org/source/openssl-1.0.2e.tar.gz
wget http://zlib.net/zlib-1.2.8.tar.gz
nginx偽證書配置
創建服務器私鑰,命令會讓你輸入一個口令:
openssl genrsa -des3 -out server.key 1024
創建簽名請求的證書(CSR):
openssl req -new -key server.key -out server.csr
在加載SSL支持的Nginx并使用上述私鑰時除去必須的口令:
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
具體配置參考
http://nginx.org/en/docs/http/ngx_http_v2_module.html
server { listen 443 ssl http2; ssl_certificate server.crt; ssl_certificate_key server.key; }
這里請求完成之后連接是保持的,直到超時才會關閉連接
具體想了解http2到底是什么可自行百度了解更多~