From 9173503b04369438c39edeac0f16dfb70b99695a Mon Sep 17 00:00:00 2001 From: fanxb Date: Tue, 7 May 2019 19:45:50 +0800 Subject: [PATCH] add --- ...(非atp).md => 3.linux下mongodb的安装与配置(非atp).md} | 0 linux/软件安装/4.linux编译安装openssl.md | 73 +++++++++++++++++++ linux/软件安装/5.nginx多ssl配置.md | 68 +++++++++++++++++ 3 files changed, 141 insertions(+) rename linux/软件安装/{linux下mongodb的安装与配置(非atp).md => 3.linux下mongodb的安装与配置(非atp).md} (100%) create mode 100644 linux/软件安装/4.linux编译安装openssl.md create mode 100644 linux/软件安装/5.nginx多ssl配置.md diff --git a/linux/软件安装/linux下mongodb的安装与配置(非atp).md b/linux/软件安装/3.linux下mongodb的安装与配置(非atp).md similarity index 100% rename from linux/软件安装/linux下mongodb的安装与配置(非atp).md rename to linux/软件安装/3.linux下mongodb的安装与配置(非atp).md diff --git a/linux/软件安装/4.linux编译安装openssl.md b/linux/软件安装/4.linux编译安装openssl.md new file mode 100644 index 0000000..49d3a08 --- /dev/null +++ b/linux/软件安装/4.linux编译安装openssl.md @@ -0,0 +1,73 @@ +--- +id: "20190503" +date: "2019/05/03 10:38:05" +title: "linux下编译安装openssl" +tags: ["linux", "ubuntu", "openssl"] +categories: + - "linux" + - "软件安装" +--- + +linux 上安装软件通常有两种办法: + +- 从软件包仓库安装 +- 源码编译安装 + +第一种方式很简单,一条命令就搞定。 + +```bash +# debian系列 +apt install openssl +# centos系列 +yum install openssl +``` + +但是上面的方法无法配置参数,有些功能必须要手动编译才能开启。比如`enable-tlsext`,开启这个参数让 openssl 支持 SSL SNI(一个 IP 绑定多个证书)。步骤如下: + + + +1. 下载源码包 + +有些版本的 openssl 不支持`enable-tlsext`参数,目前 1.0.2r 版本是支持的。 + +```bash +wget https://www.openssl.org/source/openssl-1.0.2r.tar.gz +``` + +2. 卸载自带 openssl + +注意可能会连带卸载很多依赖于 openssl 的软件。 + +```bash +sudo apt remove openssl +``` + +3. 解压 + +```bash +tar -zxf openssl-1.0.2r.tar.gz +``` + +4. 配置 + +```bash +cd openssl-1.0.2r +sudo ./config shared enable-tlsext --prefix=/usr/local/openssl --openssldir=/usr/lib/openssl +``` + +5. 编译安装 + +```bash +make +sudo make install +``` + +6. 配置环境变量 + +编辑`/etc/environment`,注意要以`:`分割 + +![](https://raw.githubusercontent.com/FleyX/files/master/blog/20190503125650.png) + +输入`source /etc/environment`让环境变量生效,即安装完成。 + +**本文原创发布于:**[https://www.tapme.top/blog/detail/20190503](https://www.tapme.top/blog/detail/20190503) \ No newline at end of file diff --git a/linux/软件安装/5.nginx多ssl配置.md b/linux/软件安装/5.nginx多ssl配置.md new file mode 100644 index 0000000..1eeb58e --- /dev/null +++ b/linux/软件安装/5.nginx多ssl配置.md @@ -0,0 +1,68 @@ +--- +id: "20190504" +date: "2019/05/04 10:38:05" +title: "nginx配置多ssl证书" +tags: ["linux", "nginx", "多ssl证书"] +categories: + - "linux" + - "软件使用" +--- + +有时我们需要在一台主机(只有一个公网 ip)上部署多个 https 虚拟主机,如何实现呢? + +假如我们想当然的使用如下的配置: + +```properties +server{ + listen 443 default ssl; + server_name www.test1.com; + ssl_certificate xxxxx; + ssl_certificate_key xxxxx; +} + +server{ + listen 443 ssl; + server_name www.test2.com; + ssl_certificate xxxxx; + ssl_certificate_key xxxxx; +} +``` + + + +当然是无法实现的,不论请求哪个主机,都只会收到默认域名`www.test1.com`的证书,这是 SSL 协议本身造成的--先建立 SSL 连接,再发送 HTTP 请求,因此 nginx 建立 SSL 连接时并不知道所请求的域名,所以只会返回默认的主机。 + +# 解决办法 + +## 使用多个 IP + +最古老的办法就是使用多个 IP,每个域名绑定到一个 IP 上即可。 + +## 使用 TLS SNI + +使用多 IP 的方法成本太高了,还好 nginx 支持 TLS 协议的 SNI 拓展(这个拓展让同一个 IP 使用不同的 https 证书成为可能)。SNI 拓展需要客户端支持(一般都支持),本地 OpenSSL 支持(这个默认都是不支持的,需要手动编译支持)。 + +查看 nginx 知否支持 SNI,使用如下命令: + +```bash +nginx -V +``` + +有如下输出说明支持 SNI。 + +![](https://raw.githubusercontent.com/FleyX/files/master/blog/20190504152556.png) + +默认情况下是不支持的,下面我们来一步一步让它支持 SNI: + +1. 首先要重新编译安装 openssl,详情参考我之前的博文:[https://blog.tapme.top/blog/detail/20190503](https://blog.tapme.top/blog/detail/20190503) + +2. openssl 支持 SNI 后,重装一次 nginx 理论上就可以了(至少我是这样的): + +```bash +apt remove nginx +apt install nginx +``` + +然后就可以在一个 IP 上使用多个不同的 https 证书了. + +**本文原创发布于:**[https://www.tapme.top/blog/detail/20190504](https://www.tapme.top/blog/detail/20190504)