Nginx实现多域名证书HTTPS

简介:

目前公司有2个域名,其中这次涉及到3个子域名需要更改为HTTPS传输,分别为:

passport.abc.com

www.test.com

admin.test.com

那么就涉及到购买ssl证书的问题,由于价格问题使用3个不同的证书(每个域名一个)。

由于实验环境,我们就手动生成3个ssl证书

建立目录,及进入目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@gz122haproxy95 ~] # mkdir ~/keys
[root@gz122haproxy95 keys] # cd ~/keys
[root@gz122haproxy95 keys] # openssl genrsa -out passport.abc.com.key 2048
[root@gz122haproxy95 keys] # openssl req -new -key passport.abc.com.key -out passport.abc.com.csr
 
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter  '.' , the field will be left blank.
-----
Country Name (2 letter code) [GB]:CN    #国家
State or Province Name (full name) [Berkshire]:GuangDong   #省份
Locality Name (eg, city) [Newbury]:ShenZhen    #城市
Organization Name (eg, company) [My Company Ltd]:Test.Inc     #公司名称
Organizational Unit Name (eg, section) []:passport.abc.com     #组织名称
Common Name (eg, your name or your server's  hostname ) []:passport.abc.com    #域名
Email Address []:passport@abc.com
Please enter the following  'extra'  attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
 
[root@gz122haproxy95 keys] # openssl x509 -req -days 3650 -in passport.abc.com.csr -signkey passport.abc.com.key -out passport.abc.com.crt

按照以上方法,把名称替换掉再制作2份,最后的结果就是

1
2
3
4
5
6
7
8
9
10
11
[root@gz122haproxy95 keys] # ls -l
total 36
-rw-r--r-- 1 root root 1354 Dec  4 16:54 admin. test .com.crt
-rw-r--r-- 1 root root 1050 Dec  4 16:54 admin. test .com.csr
-rw-r--r-- 1 root root 1675 Dec  4 16:52 admin. test .com.key
-rw-r--r-- 1 root root 1354 Dec  4 16:48 passport.abc.com.crt
-rw-r--r-- 1 root root 1078 Dec  4 16:44 passport.abc.com.csr
-rw-r--r-- 1 root root 1675 Dec  4 16:41 passport.abc.com.key
-rw-r--r-- 1 root root 1354 Dec  4 16:52 www. test .com.crt
-rw-r--r-- 1 root root 1062 Dec  4 16:52 www. test .com.csr
-rw-r--r-- 1 root root 1679 Dec  4 16:51 www. test .com.key


现在就是Nginx和OpenSSL的安装与配置(这里注意,一般情况下一个IP只支持一个SSL证书,那么我们现在要在一个IP上实现多个SSL证书,就必须让Nginx支持TLS SNI,由于默认的OpenSSL是没有打开TLS SNI的)

1
2
3
4
5
6
7
8
[root@gz122haproxy95 ~] # wget 
[root@gz122haproxy95 ~] # tar zxf openssl-0.9.8zh.tar.gz  
[root@gz122haproxy95 ~] # wget http://nginx.org/download/nginx-1.8.0.tar.gz
[root@gz122haproxy95 ~] # tar zxf nginx-1.8.0.tar.gz 
[root@gz122haproxy95 ~] # cd nginx-1.8.0
[root@gz122haproxy95 nginx-1.8.0] # ./configure --prefix=/usr/local/nginx1.8.0 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=../openssl-0.9.8zh 
[root@gz122haproxy95 nginx-1.8.0] # make && make install
#上面只需要解压openssl即可,然后在nginx的配置参数中添加--with-openssl=DIR指定路径即可,另外由于openssl需要编译,所以时间会较长。

在编译安装nginx的时候可能会出现pcre库没找到或zlib没找到,在CentOS下可以使用

1
yum -y  install  pcre-devel zlib-devel


在安装编译好Nginx后,执行

1
2
3
4
5
6
[root@gz122haproxy95 nginx-1.8.0] # /usr/local/nginx1.8.0/sbin/nginx -V
nginx version: nginx /1 .8.0
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-55)
built with OpenSSL 0.9.8zh 3 Dec 2015
TLS SNI support enabled       #可以看到TLS SNI support打开了
configure arguments: --prefix= /usr/local/nginx1 .8.0 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=.. /openssl-0 .9.8zh

然后配置nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
upstream passport.abc.com {
         server 192.168.20.87:80;
         server 192.168.20.88:80;
         
}
 
     # HTTPS server
     #
     server {
         listen       443 ssl;
         server_name  passport.abc.com;
 
         ssl_certificate       /root/keys/passport .abc.com.crt;
         ssl_certificate_key   /root/keys/passport .abc.com.key;
 
         ssl_session_cache    shared:SSL:1m;
         ssl_session_timeout  5m;
 
         ssl_ciphers  HIGH:!aNULL:!MD5;
         ssl_prefer_server_ciphers  on;
 
         location / {
                 proxy_pass http: //passport .abc.com;
         }
     }
 
  upstream www. test .com {
         server 192.168.20.98:80;
         server 192.168.20.99:80;
         
}
 
     # HTTPS server
     #
     server {
         listen       443 ssl;
         server_name  www. test .com;
 
         ssl_certificate       /root/keys/www . test .com.crt;
         ssl_certificate_key   /root/keys/www . test .com.key;
 
         ssl_session_cache    shared:SSL:1m;
         ssl_session_timeout  5m;
 
         ssl_ciphers  HIGH:!aNULL:!MD5;
         ssl_prefer_server_ciphers  on;
 
         location / {
                 proxy_pass http: //www . test .com;
         }
     }


通过以上即可实现nginx的HTTPS的多域名反向代理



本文转自 rong341233 51CTO博客,原文链接:http://blog.51cto.com/fengwan/1719708

相关文章
|
1月前
|
数据建模 网络安全
阿里云SSL证书不同类型DV、OV和EV如何收费?单域名和通配符SSL价格整理
阿里云SSL证书提供免费和收费版本,涵盖DV、OV、EV多种类型。收费证书品牌包括DigiCert、GlobalSign等,价格从238元/年起。免费SSL证书由Digicert提供,单域名有效3个月,每个实名主体每年可领取20个。具体价格和详情见阿里云SSL官方页面。
|
1月前
|
数据建模 网络安全
阿里云SSL证书不同类型DV、OV和EV如何收费?单域名和通配符SSL价格整理
阿里云SSL证书提供免费和收费选项。收费证书包括:DV单域名WoSign 238元/年,DigiCert通配符DV 1500元/年,GlobalSign OV企业型1864元/年等。免费SSL证书由Digicert提供,有效期3个月,每年可领取20个单域名证书。更多详情及价格表请参考阿里云官方页面。
|
1月前
|
域名解析 安全 数据建模
没有域名只有IP地址怎么申请https证书?
IP 地址 SSL 证书是一种特殊的 SSL/TLS 证书,允许直接为 IP 地址配置 HTTPS 加密,适用于内部服务、私有网络和无域名的设备管理。与基于域名的证书不同,申请过程较为复杂,需选择支持 IP 的证书颁发机构(CA),并完成额外的身份验证步骤。浏览器对 IP 地址的支持有限,可能会显示警告。通过正确配置服务器(如 Nginx 或 Apache),可以确保通信安全。
|
2月前
|
网络协议 应用服务中间件 网络安全
免费泛域名https证书教程—无限免费续签
随着互联网安全意识提升,越来越多网站采用HTTPS协议。本文介绍如何通过JoySSL轻松获取并实现免费泛域名SSL证书的无限续签。JoySSL提供永久免费通配符SSL证书,支持无限制域名申请及自动续签,全中文界面适合国内用户。教程涵盖注册账号、选择证书类型、验证域名所有权、下载与安装证书以及设置自动续签等步骤,帮助网站简化SSL证书管理流程,确保长期安全性。
|
2月前
|
应用服务中间件 Linux 网络安全
nginx安装部署ssl证书,同时支持http与https方式访问
为了使HTTP服务支持HTTPS访问,需生成并安装SSL证书,并确保Nginx支持SSL模块。首先,在`/usr/local/nginx`目录下生成RSA密钥、证书申请文件及自签名证书。接着,确认Nginx已安装SSL模块,若未安装则重新编译Nginx加入该模块。最后,编辑`nginx.conf`配置文件,启用并配置HTTPS服务器部分,指定证书路径和监听端口(如20000),保存后重启Nginx完成部署。
866 8
|
2月前
|
Web App开发 安全 网络协议
多域名 SSL 证书是什么? 多域名 SSL 证书申请流程
多域名SSL证书是保护多个网站时的高效选择,它使得单个证书能够保护多个域名(网站)。这种证书通过在用户的Web浏览器和托管网站的服务器之间建立安全的加密连接,确保了敏感信息(包括登录凭证、信用卡信息和其他个人数据)的安全传输。
416 1
|
3月前
|
Web App开发 算法 应用服务中间件
nginx开启局域网https访问
【10月更文挑战第22天】为了调试WebRTC功能,需要在局域网内搭建HTTPS协议。具体步骤包括:在已部署Nginx和安装OpenSSL的环境中生成私钥、证书签名请求和自签名证书;将生成的文件放置到Nginx的证书目录并修改Nginx配置文件,最后重启Nginx服务。注意,自签名证书不受第三方机构认可,如需正式使用,需向CA申请签名。
128 2
|
4月前
|
网络安全
阿里云国际版如何为SSL证书更换域名?
阿里云国际版如何为SSL证书更换域名?
|
应用服务中间件 网络安全 nginx
Nginx学习研究-Nginx 安装 SSL 配置 HTTPS
Nginx学习研究-Nginx 安装 SSL 配置 HTTPS
423 0
|
4月前
|
安全 应用服务中间件 Shell
nginx配置https的ssl证书和域名
nginx配置https的ssl证书和域名