本文介紹了升級nginx以支持http2的方法,分享給大家,具體如下:
一鍵升級腳本
https://github.com/whisshe/upHttp2.git
HTTP/2 的優勢
相比 HTTP/1.x,HTTP/2 在底層傳輸做了很大的改動和優化:
升級HTTP2必要條件
軟件安裝位置
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.oldmv /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 versionif [[ `openssl version |awk '{print $2}'` == 1.1.0g ]];then echo okfi
nginx升級(源碼編譯)
原配置文件不會丟失
1、下載源碼包
wget http://nginx.org/download/nginx-1.12.2.tar.gz
2、解壓編譯安裝
編譯安裝 nginx 時,--with-openssl 參數默認只支持OpenSSL的源代碼,不支持已編譯好的 OpenSSL。可以在nginx的解壓目錄下修改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.confldconfig -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
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答