升級(jí)nginx以支持http2的方法
本文介紹了升級(jí)nginx以支持http2的方法,分享給大家,具體如下:
一鍵升級(jí)腳本
https://github.com/whisshe/upHttp2.git
HTTP/2 的優(yōu)勢(shì)
相比 HTTP/1.x,HTTP/2 在底層傳輸做了很大的改動(dòng)和優(yōu)化:
- HTTP/2 采用二進(jìn)制格式傳輸數(shù)據(jù),而非 HTTP/1.x 的文本格式。二進(jìn)制格式在協(xié)議的解析和優(yōu)化擴(kuò)展上帶來(lái)更多的優(yōu)勢(shì)和可能。
- HTTP/2 對(duì)消息頭采用 HPACK 進(jìn)行壓縮傳輸,能夠節(jié)省消息頭占用的網(wǎng)絡(luò)的流量。而 HTTP/1.x 每次請(qǐng)求,都會(huì)攜帶大量冗余頭信息,浪費(fèi)了很多帶寬資源。頭壓縮能夠很好的解決該問題。
- 多路復(fù)用,直白的說就是所有的請(qǐng)求都是通過一個(gè) TCP 連接并發(fā)完成。HTTP/1.x 雖然通過 pipeline 也能并發(fā)請(qǐng)求,但是多個(gè)請(qǐng)求之間的響應(yīng)會(huì)被阻塞的,所以 pipeline 至今也沒有被普及應(yīng)用,而 HTTP/2 做到了真正的并發(fā)請(qǐng)求。同時(shí),流還支持優(yōu)先級(jí)和流量控制。
- Server Push:服務(wù)端能夠更快的把資源推送給客戶端。例如服務(wù)端可以主動(dòng)把 JS 和 CSS 文件推送給客戶端,而不需要客戶端解析 HTML 再發(fā)送這些請(qǐng)求。當(dāng)客戶端需要的時(shí)候,它已經(jīng)在客戶端了。
升級(jí)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
升級(jí)所有游戲服務(wù)器的nginx和OpenSSL
升級(jí)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、驗(yàn)證openssl版本信息
openssl version if [[ `openssl version |awk '{print $2}'` == 1.1.0g ]];then echo ok fi
nginx升級(jí)(源碼編譯)
原配置文件不會(huì)丟失
1、下載源碼包
wget http://nginx.org/download/nginx-1.12.2.tar.gz
2、解壓編譯安裝
編譯安裝 nginx 時(shí),--with-openssl 參數(shù)默認(rèn)只支持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;
出現(xiàn)的問題及解決
centos7下openssl version報(bào)錯(cuò)openssl: error while loading shared libraries: libssl.so.1.1
echo /usr/local/openssl/lib >> /etc/ld.so.conf # 將openssl編譯路徑的lib庫(kù)加入到/etc/ld.so.conf ldconfig -v|grep libssl # 檢查是否添加成功
nginx重啟出現(xiàn)錯(cuò)誤,nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed
ls -l /var/cache/nginx/client_temp#檢查該文件夾是否存在和文件夾的權(quán)限 mkdir -p /var/cache/nginx/client_temp #文件夾不存在則生成文件夾 chown -R www-data:www-data /var/cache/nginx/client_temp # 將文件夾所有者和組改為nginx的運(yùn)行用戶,具體見nginx.conf
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
負(fù)載均衡的基本知識(shí)以及使用nginx進(jìn)行負(fù)載均衡的簡(jiǎn)單例子
今天小編就為大家分享一篇關(guān)于負(fù)載均衡的基本知識(shí)以及使用nginx進(jìn)行負(fù)載均衡的簡(jiǎn)單例子,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-12-12Nginx服務(wù)器的location指令匹配規(guī)則詳解
這篇文章主要介紹了Nginx服務(wù)器的location指令匹配規(guī)則,文中介紹了一種動(dòng)靜態(tài)地址分離的方法示例,需要的朋友可以參考下2015-12-12Windows下使用?Nginx?搭建?HTTP文件服務(wù)器?實(shí)現(xiàn)文件下載功能
Nginx?是一款輕量級(jí)的?HTTP?服務(wù)器,采用事件驅(qū)動(dòng)的異步非阻塞處理方式框架,這讓其具有極好的?IO?性能,時(shí)常用于服務(wù)端的反向代理和負(fù)載均衡,這篇文章主要介紹了Windows下使用?Nginx?搭建?HTTP文件服務(wù)器實(shí)現(xiàn)文件下載功能,需要的朋友可以參考下2023-03-03ubuntu上配置Nginx+PHP5 FastCGI服務(wù)器配置
ubuntu上配置Nginx+PHP5 FastCGI服務(wù)器配置方法, 需要的朋友可以參考下。2010-06-06詳解Nginx反向代理實(shí)現(xiàn)Kibana登錄認(rèn)證功能
這篇文章主要介紹了詳解Nginx反向代理實(shí)現(xiàn)Kibana登錄認(rèn)證功能,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2018-06-06Jenkins實(shí)現(xiàn)集群化管理以及流水線項(xiàng)目配置
這篇文章主要為大家介紹了Jenkins基本概念,配置實(shí)現(xiàn)集群化管理以及配置流水線項(xiàng)目的實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03