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

相关文章
|
8月前
|
应用服务中间件 Linux 网络安全
Centos 8.0中Nginx配置文件和https正书添加配置
这是一份Nginx配置文件,包含HTTP与HTTPS服务设置。主要功能如下:1) 将HTTP(80端口)请求重定向至HTTPS(443端口),增强安全性;2) 配置SSL证书,支持TLSv1.1至TLSv1.3协议;3) 使用uWSGI与后端应用通信(如Django);4) 静态文件托管路径设为`/root/code/static/`;5) 定制错误页面(404、50x)。适用于Web应用部署场景。
850 87
|
11月前
|
安全 算法 网络协议
解析:HTTPS通过SSL/TLS证书加密的原理与逻辑
HTTPS通过SSL/TLS证书加密,结合对称与非对称加密及数字证书验证实现安全通信。首先,服务器发送含公钥的数字证书,客户端验证其合法性后生成随机数并用公钥加密发送给服务器,双方据此生成相同的对称密钥。后续通信使用对称加密确保高效性和安全性。同时,数字证书验证服务器身份,防止中间人攻击;哈希算法和数字签名确保数据完整性,防止篡改。整个流程保障了身份认证、数据加密和完整性保护。
求助!怎么上传第三方HTTPS证书?为什么我上传lets encrypt的证书显示私钥格式异常?
用户上传证书时遇到问题,提示格式异常,已尝试转换RSA格式仍未解决。
|
6月前
|
人工智能 安全 算法
HTTPS 的「秘钥交换 + 证书校验」全流程
HTTPS 通过“证书如身份证、密钥交换如临时暗号”的握手流程,实现身份认证与数据加密双重保障,确保通信安全可靠。
671 0
|
12月前
|
数据建模 网络安全
阿里云SSL证书不同类型DV、OV和EV如何收费?单域名和通配符SSL价格整理
阿里云SSL证书提供免费和收费版本,涵盖DV、OV、EV多种类型。收费证书品牌包括DigiCert、GlobalSign等,价格从238元/年起。免费SSL证书由Digicert提供,单域名有效3个月,每个实名主体每年可领取20个。具体价格和详情见阿里云SSL官方页面。
|
10月前
|
网络协议
【Azure App Service】App Service 如何配置私网域名以及证书呢?
本文解答了关于 Azure App Service 如何配置私网域名及证书的问题。App Service 不支持私网域名,自定义域名需配置在公共 DNS 服务器上。文章引用官方文档详细说明了映射自定义 DNS 的步骤,并附带参考资料链接,帮助用户深入了解相关配置方法。
251 6
|
12月前
|
监控 运维
HTTPS 证书自动化运维:https证书管理系统- 自动化监控
本文介绍如何设置和查看域名或证书监控。步骤1:根据证书状态选择新增域名或证书监控,线上部署推荐域名监控,未部署选择证书监控。步骤2:查询监控记录详情。步骤3:在详情页查看每日定时检测结果或手动测试。
HTTPS 证书自动化运维:https证书管理系统- 自动化监控
|
12月前
|
Linux 持续交付 调度
HTTPS 证书自动化运维:https证书管理系统-自动化部署
本指南介绍如何部署Linux服务器节点。首先复制生成的Linux脚本命令,然后将其粘贴到目标服务器上运行。接着刷新页面查看节点记录,并点击“配置证书”选择证书以自动部署。最后,节点部署完成,后续将自动调度,无需人工干预。
HTTPS 证书自动化运维:https证书管理系统-自动化部署
|
12月前
|
运维
HTTPS 证书自动化运维:https证书管理系统之自动化签发
通过访问【https://www.lingyanspace.com】注册账户,进入证书服务菜单并新增证书。填写域名(单域名、多域名或泛域名),创建订单后添加云解析DNS记录进行质检。确认完成后可下载证书,并支持后续查看、更新和定时更新功能。证书过期前15天自动更新,需配置邮箱接收通知。
HTTPS 证书自动化运维:https证书管理系统之自动化签发
|
9月前
|
安全 算法 数据建模
HTTPS证书类型和品牌一览
HTTPS证书(SSL证书)是保障网站数据传输安全与身份可信认证的重要工具,适用于电商、企业官网等各类平台。证书主要分为DV(域名验证)、OV(企业验证)、EV(扩展验证)三种安全级别,以及单域名、通配符、多域名等不同覆盖类型。品牌方面,既有高性价比的国产锐安信、CFCA,也有国际知名的Sectigo、Digicert。