Nginx实现多域名证书HTTPS
目前公司有2个域名,其中这次涉及到3个子域名需要更改为HTTPS传输,分别为:
passport.abc.com
www.test.com
admin.test.com
那么就涉及到购买ssl证书的问题,由于价格问题使用3个不同的证书(每个域名一个)。
由于实验环境,我们就手动生成3个ssl证书
建立目录,及进入目录
[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份,最后的结果就是
[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的)
[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下可以使用
yum -y install pcre-devel zlib-devel
在安装编译好Nginx后,执行
[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
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的多域名反向代理
Nginx实现多域名证书HTTPS的更多相关文章
- [转帖]一个ip对应多个域名多个ssl证书配置-Nginx实现多域名证书HTTPS
一个ip对应多个域名多个ssl证书配置-Nginx实现多域名证书HTTPS https://home.cnblogs.com/u/beyang/ 一台服务器,两个域名 首先购买https,获取到CA证 ...
- 一个ip对应多个域名多个ssl证书配置-Nginx实现多域名证书HTTPS
一台服务器,两个域名 首先购买https,获取到CA证书,两个域名就得到两套证书 第二步:现在就是Nginx和OpenSSL的安装与配置(这里注意,一般情况下一个IP只支持一个SSL证书,那么我们现在 ...
- nginx 的多域名多https转发设置方法【转】
version: 1.1(fixed) 修正一些错误基本环境:/etc/nginx/nginx.conf #保持/etc/nginx/ssl/ #ssl认证文件/etc/nginx/site-a ...
- Nginx多个域名,https redirect to http
背景描述:Nginx绑定多个域名,其中一个域名配置了https,如域名A:https://www.aaa.com:另外的域名B(http://www.bbb.com)没有配置SSL证书, 问题:以ht ...
- haproxy 实现多域名证书https
[root@ha02 keys]# openssl genrsa - Generating RSA bit long modulus ....+++ ......................... ...
- Nginx实现ssl一级、二级域名证书部署并用https访问代理转发服务器
1. 规划 域名 解析IP Nginx代理 htpps://www.devcult.com 47.88.10.155 htpps://auto.devcult.com 47.88.10.155 ...
- 使用SSL安全证书和nginx配置将域名HTTPS化
一.在阿里云后台申请免费版证书: 二.在域名解析里面添加记录: 三.提交审核: 四.等待审核通过后,下载nginx证书: 五.按照文档修改nginx配置文件: https://help.aliyun. ...
- Nginx配置同一个域名同时支持http与https两种方式访问
Nginx配置同一个域名http与https两种方式都可访问,证书是阿里云上免费申请的 server{listen 80;listen 443 ssl;ssl on;server_name 域名;in ...
- [从零开始搭网站六]为域名申请免费SSL证书(https),并为Tomcat配置https域名所用的多SSL证书
点击下面连接查看从零开始搭网站全系列 从零开始搭网站 由于国内的网络环境比较恶劣,运营商流量劫持的情况比较严重,一般表现为别人打开你的网站的时候会弹一些莫名其妙的广告...更过分的会跳转至别的网站. ...
随机推荐
- ReactNative中iOS和Android的style分开设置教程
reactnative可以编辑iOS程序也可以编辑Android程序, 而且80%的代码都可以重用. 及有些文件是两个系统通用的, 相信大家也都清楚了. 但是也许大家会遇到一些屏幕布局的问题, 最常遇 ...
- ubuntu自动执行
一般先写个sh脚本文件---->要执行的语句写入sh文件----->chromd -x ???.sh增加权限即可 crontab -e * * * * * /home/???.sh */1 ...
- response和request的区别以及常见问题解决
request是请求,即客服端发来的请求 response是响应,是服务器做出的响应 --------------------------------------------------------- ...
- (八)数据呈现——一图胜千言<完结>
数据分析师就像厨师一样.厨师的工作有5步:下单.备料.切配.烹饪.打荷.数据分析师的工作也有5步.呈现数据就好像打荷.厨师在把菜肴端给客人之前要做盘饰美化,让菜肴精致美观,这个工作就是打荷.同样,数据 ...
- 【FLUENT案例】01:T型管混合器中的流动与传热
案例目录 1 引子1.1 案例描述1.2 案例学习目标2 计算仿真目标3 启动FLUENT并读入网格4 FLUENT工作界面5 网格缩放及检查6 修改单位7 设置模型8 定义新材料9 计算域设置10 ...
- Unity性能优化(1)-官方教程The Profiler window翻译
本文是Unity官方教程,性能优化系列的第一篇<The Profiler window>的简单翻译. 相关文章: Unity性能优化(1)-官方教程The Profiler window翻 ...
- bash/shell编程学习(3)
接上节继续, 1. 从键盘读取输入内容 #!/bin/bash read -p 'please input something:' input echo 'your input:' $input 运行 ...
- 51Nod 1278 相离的圆
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...
- oracle日常——sqlplus客户端登录
1.进入cmd 2.命令--sqlplus--提示输入帐号与密码 3.进入后,就可以直接键入sql命令 ps.sql命令后面需要添加分号后才可以回车执行
- 基本组件的使用——UINavigationController
作用:在多个ViewController中切换.UINavigationController内部以栈的形式维护一组ViewController, 因此,当导航进入一个新视图的时候,会以push的形式将 ...