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证书
点击下面连接查看从零开始搭网站全系列 从零开始搭网站 由于国内的网络环境比较恶劣,运营商流量劫持的情况比较严重,一般表现为别人打开你的网站的时候会弹一些莫名其妙的广告...更过分的会跳转至别的网站. ...
随机推荐
- iOS 开发者账号到期续费流程
1.登录developer.apple.com,查看到期时间 2.到期提醒通知,点击Renew Membership续费(一般提前一个月提醒续费) 3.个人开发者账号续费需要支付 688人民币/年(9 ...
- PullToRefreshListView的使用
- ios动态创建类Class
[Objective-C Runtime动态加载]---动态创建类Class 动态创建类Class,动态添加Class成员变量与成员函数,动态变量赋值与取值,动态函数调用等方法 a.使用objc_al ...
- nginx实现单服务代理多域名
通过一台nginx服务器代理多个域名进行跳转,原理很简单,重点在玩法!适用于公司处理域名紧急备案问题. 域名: www.hx123.com www.hx456.com nginx服务器: ginx.c ...
- css之定位
定位有三种,分别是相对定位 position:relative; .绝对定位 position:absolute; .固定定位 position:fixed; 相对定位 相对定位,就是微调元素位置的, ...
- PHP求职宝典系列——PHP Web 编程篇
PHP Web 编程篇 form表单 1.简述 POST 和 GET 传输的最大容量分别是多少? GET 方法提交的表单数据被附加到 URL 上,并作为URL 的一部分发送到服务器端. URL 的长度 ...
- 关于IOS调用微信支付jsapi不起作用的解决方法
微信支付时,安卓机调用 jsapi可以支付,IOS就不行,点击立即支付,直接返回原立即支付页面,跟刷新页面差不多,解决方案很简单:两句话而已. 不得不说,微信支付坑太多了,我擦..... <sc ...
- Js函数function基础理解
正文:我们知道,在js中,函数实际上是一个对象,每个函数都是Function类型的实例,并且都与其他引用类型一样具有属性和方法.因此,函数名实际上是指向函数对象的指针,不与某个函数绑定.在常见的两种定 ...
- [LeetCode] Same Tree 判断相同树
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- [LeetCode] Longest Common Prefix 最长共同前缀
Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...