Nginx开启http2


h2有很多好处,比如流量更小、tcp连接数更少、多路复用、服务器推送、头部压缩等。所以在nginx上开启h2

安装最新版本的openssl
wget https://www.openssl.org/source/openssl-1.0.2s.tar.gz
tar xzf openssl-1.0.2s.tar.gz
cd openssl-1.0.2s
./config --prefix=/opt/openssl
make
make install

#这一步是升级整个系统的openssl版本和库,可以不更改系统级
mv /usr/bin/openssl /usr/bin/openssl.bak
ls /usr/include/openssl/
mv /usr/include/openssl /usr/include/openssl.bak
ln -s /opt/openssl/bin/openssl /usr/bin/openssl
openssl version
ln -s /opt/openssl/include/openssl /usr/include/openssl
检查版本
openssl version
openssl version -a


#安装编译nginx
wget http://nginx.org/download/nginx-1.17.0.tar.gz
tar xzf nginx-1.17.0.tar.gz
cd nginx-1.17.0

vim auto/lib/openssl/conf
$OPENSSL/.openssl 更改为$OPENSSL/

export PKG_CONFIG_PATH=/opt/openssl/lib/pkgconfig
export LD_LIBRARY_PATH=/opt/openssl/lib

./configure --prefix=/opt/nginx --with-stream --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_v2_module --with-openssl=/opt/openssl/

make
make install
/opt/nginx/sbin/nginx -V
/opt/nginx/sbin/nginx -t
pkill nginx
/opt/nginx/sbin/nginx

在相关https配置后面加入:

listen 443 ssl http2;
Devops