关注小众语言,记录、分享技术点滴!

0%

nginx(openresty)升级ssl模块 以支持 HTTP/2

我们并不需要升级系统自带的 openssl,因为随便升级 openssl 会带来安全风险。我们只下载 openssl 1.0.2 源码包,借助它来重新编译(相当于重新安装)服务器上的 NginX 即可。一旦成了 built with OpenSSL 1.0.2,就意味着能够支持 http/2 了。

1、下载并解压 OpenSSL

1
2
3
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.2-latest.tar.gz
tar -zxf openssl-1.0.2-latest.tar.gz

2、修改编译参数

#####指定opensll包位置
--with-openssl=/usr/local/src/openssl-1.0.2m

#####开启ssl模块
--with-http_ssl_module

#####开启http/2模块
--with-http_v2_module

#####编译报错是“collect2: ld returned 1 exit status”需要指定pcre8.36及以上版本
--with-pcre=/usr/local/src/pcre-8.40

3、开启ssl 修改配置

1
2
3
4
5
server {
listen 443 ssl;
server_name localhost;
....
}

4、开启http/2 修改配置

1
2
3
4
5
server {
listen 443 ssl http2;
server_name localhost;
....
}

附:
pcre下载:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/