文章主要介绍了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

  1. $ nginx -V
  2. ...
  3. TLS SNI support enabled
  4. ...

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

具体步骤如下:

首先下载openssl(建议下载1.0.1h版本)

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

下载Nginx

  1. #wget http://nginx.org/download/nginx-1.9.9.tar.gz

解压openssl

  1. #tar -zxvf openssl-1.0.1h.tar.gz

解压nginx,并编译

  1. #tar -zxvf nginx-1.9.9.tar.gz
  2. #cd nginx-1.9.9
  3. #./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/
  4. #make && make install

#检查Nginx版本信息

  1. #/usr/local/nginx/sbin/nginx -V
  1. nginx version: nginx/1.9.9
  2. built by gcc 4.1.2 20080704 (Red Hat 4.1.2-55)
  3. built with OpenSSL 1.0.1h 5 Jun 2014
  4. TLS SNI support enabled
  5. 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中的域名证书

  1. server
  2.     {
  3.      #########
  4.         listen 80;
  5.         listen 443 ssl;
  6.         #listen [::]:80;
  7.         server_name we.baohua.me;
  8.         root  /home/wwwroot/we.baohua.me;
  9.  
  10.         ssl on;
  11.         ssl_certificate_key /home/wwwroot/cert/we.baohua.me.key;
  12.         ssl_certificate /home/wwwroot/cert/we.baohua.me.crt;
  13.         ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  14.         ssl_ciphers HIGH:!aNULL:!MD5;
  15.      ###############
  16. }

然后,重启Nginx即可。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。