小編給大家分享一下如何升級nginx以支持http2,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
一鍵升級腳本
https://github.com/whisshe/upHttp2.git
HTTP/2 的優勢
相比 HTTP/1.x,HTTP/2 在底層傳輸做了很大的改動和優化:
HTTP/2 采用二進制格式傳輸數據,而非 HTTP/1.x 的文本格式。二進制格式在協議的解析和優化擴展上帶來更多的優勢和可能。
HTTP/2 對消息頭采用 HPACK 進行壓縮傳輸,能夠節省消息頭占用的網絡的流量。而 HTTP/1.x 每次請求,都會攜帶大量冗余頭信息,浪費了很多帶寬資源。頭壓縮能夠很好的解決該問題。
多路復用,直白的說就是所有的請求都是通過一個 TCP 連接并發完成。HTTP/1.x 雖然通過 pipeline 也能并發請求,但是多個請求之間的響應會被阻塞的,所以 pipeline 至今也沒有被普及應用,而 HTTP/2 做到了真正的并發請求。同時,流還支持優先級和流量控制。
Server Push:服務端能夠更快的把資源推送給客戶端。例如服務端可以主動把 JS 和 CSS 文件推送給客戶端,而不需要客戶端解析 HTML 再發送這些請求。當客戶端需要的時候,它已經在客戶端了。
升級HTTP2必要條件
1.10.0版本以上的nginx基于1.0.2以上版本的openssl編譯
必須支持https
軟件安裝位置
openssl
1、編譯位置
/usr/local/openssl
2、軟鏈接位置
/usr/bin/openssl
/usr/include/openssl
nginx
1、編譯及配置文件位置
/etc/nginx
升級所有游戲服務器的nginx和OpenSSL
升級openssl
1、將舊版本的openssl備份
mv /usr/bin/openssl /usr/bin/openssl.old mv /usr/include/openssl /usr/include/openssl.old
2、下載1.1版本的openssl,并解壓編譯
wget https://www.openssl.org/source/openssl-1.1.0g.tar.gz tar zxvf openssl-1.1.0g.tar.gz cd openssl-1.1.0g/ ./config --prefix=/usr/local/openssl shared zlib make depend make && make install ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl ln -s /usr/local/openssl/include/openssl /usr/include/openssl(選) cd /usr/local/openssl/lib ln -s libssl.so.1.1 libcrypto.so.1.1 /lib/x86_64-linux-gnu/ echo /usr/local/openssl/lib >> /etc/ld.so.conf
3、驗證openssl版本信息
openssl version if [[ `openssl version |awk '{print $2}'` == 1.1.0g ]];then echo ok fi
nginx升級(源碼編譯)
原配置文件不會丟失
1、下載源碼包
wget http://nginx.org/download/nginx-1.12.2.tar.gz
2、解壓編譯安裝
編譯安裝 nginx 時,--with-openssl 參數默認只支持OpenSSL的源代碼,不支持已編譯好的 OpenSSL??梢栽趎ginx的解壓目錄下修改auto/lib/openssl/conf
sed "s/.openssl\///" c
將文件中的.openssl去掉,就可以支持編譯之后的openssl路徑了
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include" CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h" CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a" CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
正式編譯
./configure --prefix=/etc/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-http_auth_request_module \ --with-threads \ --with-stream \ --with-stream_ssl_module \ --with-http_slice_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-http_v2_module \ --with-openssl=/usr/local/openssl
修改nginx配置
listen 443 ssl http2;
出現的問題及解決
centos7下openssl version報錯openssl: error while loading shared libraries: libssl.so.1.1
echo /usr/local/openssl/lib >> /etc/ld.so.conf # 將openssl編譯路徑的lib庫加入到/etc/ld.so.conf ldconfig -v|grep libssl # 檢查是否添加成功
nginx重啟出現錯誤,nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed
ls -l /var/cache/nginx/client_temp#檢查該文件夾是否存在和文件夾的權限 mkdir -p /var/cache/nginx/client_temp #文件夾不存在則生成文件夾 chown -R www-data:www-data /var/cache/nginx/client_temp # 將文件夾所有者和組改為nginx的運行用戶,具體見nginx.conf
以上是“如何升級nginx以支持http2”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創新互聯成都網站設計公司行業資訊頻道!
另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
本文標題:如何升級nginx以支持http2-創新互聯
文章來源:http://vcdvsql.cn/article30/jsppo.html
成都網站建設公司_創新互聯,為您提供小程序開發、網站收錄、做網站、品牌網站建設、品牌網站制作、網站營銷
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯