默认情况下Nginx在同一台服务器下,多个虚拟主机只能使用一个SSL证书,如果想支持的话需要在Nginx下开启TLS协议的SNI扩展(Server Name Indication)。可以使用nginx -V命令查看是否支持TLS SNI,如果显示TLS SNI support disabled则需要重新编译nginx。
首先输入 openssl version -a
命令查看系统当前使用的OpenSSL版本,后面的-a可以查看更详细的版本信息,包括一些依赖库。因为近期一些老的版本的openssl爆出了heart bleed漏洞,因此需要下载编译最新版的openssl,并开启TLS EXT,执行脚本如下:
wget https://www.openssl.org/source/openssl-1.0.2-latest.tar.gz --no-check-certificate
tar xzvf openssl-1.0.2*.tar.gz
cd openssl-1.0.2*
./config enable-tlsext --prefix=/usr/local/openssl
make && make install
将系统默认的openssl替换成新安装的openssl:
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/include/openssl /usr/include/openssl.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
echo "/usr/local/openssl/lib">>/etc/ld.so.conf
ldconfig -v
可以再次通过 openssl version -a
查看OpenSSL的版本及依赖信息。
接下来下载最新版nginx,在配置的时候加上--with-openssl和--with-openssl-opt参数,脚本如下:
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-google_perftools_module --with-openssl=<your openssl source path> --with-openssl-opt="enable-tlsext"
上面的配置信息中 --with-http_ssl_module
表示在nginx中启用SSL模块,--with-openssl
是指定openssl的源码路径,不是openssl安装之后的路径,否则会出现下面的错误:
make[1]: Entering directory `/root/nginx-1.6.2'
cd /server/openssl \
&& make clean \
&& ./config --prefix=/server/openssl/openssl no-shared no-threads \
&& make \
&& make install
make[2]: Entering directory `/server/openssl'
make[2]: *** No rule to make target `clean'. Stop.
make[2]: Leaving directory `/server/openssl'
make[1]: *** [/server/openssl/openssl/include/openssl/ssl.h] Error 2
make[1]: Leaving directory `/root/nginx-0.7.61'
make: *** [build] Error 2
©2018-2020 hongshali.com 版权所有 ICP证:闽ICP备18029655号-1