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

2

3

4

$ nginx -V

...

TLS SNI support enabled

...

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

2

3

4

#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版本信息

?

1

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

?

1

2

3

4

5

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中的域名证书

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

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即可。

猜你喜欢

转载自blog.csdn.net/zhujibcom/article/details/92370275
今日推荐