0

Nginx单IP地址配置多个SSL证书

默认情况下,Nginx一个IP地址仅支持一个SSL证书,需要多个IP地址才能配置多个SSL证书,在公网IP地址有限的情况下,可以使用TLS Server Name Indication extension(SNI, RFC 6066),它允许浏览器在SSL握手的时候发送请求的server name,也就是 Host,这样 Nginx 就能找到对应server 的SSL配置。

配置步骤如下:

1、检查Nginx是否支持TLS

$ nginx -V

TLS SNI support enabled

$ nginx -V

TLS SNI support enabled

2、如果出现TLS SNI support disable,就得升级openssl版本,并且重新编译nginx。

具体步骤如下:
首先下载openssl(建议下载1.0.1h版本)

#wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz

下载Nginx

#wget http://nginx.org/download/nginx-1.9.9.tar.gz
解压openssl

#tar -zxvf openssl-1.0.1h.tar.gz
解压nginx,并编译

#tar -zxvf nginx-1.9.9.tar.gz
#cd nginx-1.9.9
#./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-ipv6 –with-openssl=../openssl-1.0.1h/
#make && make install
#检查Nginx版本信息

#/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.9.9
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-55)
built with OpenSSL 1.0.1h 5 Jun 2014
TLS SNI support enabled
configure arguments: –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-ipv6 –with-openssl=../openssl-1.0.1h/

配置Vhost中的域名证书

server
{
#########
listen 80;
listen 443 ssl;
#listen [::]:80;
server_name we.baohua.me;
root /home/wwwroot/we.baohua.me;

ssl on;
ssl_certificate_key /home/wwwroot/cert/we.baohua.me.key;
ssl_certificate /home/wwwroot/cert/we.baohua.me.crt;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
###############
}
然后,重启Nginx即可。

参考1:https://baohua.me/middleware/nginx/nginx-single-ip-address-to-configure-multiple-ssl-certificates/
参考2:http://blog.chinaunix.net/uid-20639775-id-3213595.html
参考3:http://blog.csdn.net/cccallen/article/details/6672451

天边的星星