平常开发要求比较低, 依然在用 HTTP, 但到了微信小程序就不行了, 腾讯和苹果都对 API 提出了 HTTPS 的要求. 尤其是苹果, 不仅要求 HTTPS, 还要求 TLS 协议版本要在 1.2 以上, 这又被称为 App Transport Security(ATS).

关于自己的标准是否满足 ATS, 可以使用此工具检测: ATS(App Transport Security)检测.

服务器配置

使用 Nginx 进行 HTTPS 配置, 服务器几乎不用做改动, 依旧是祖传的 8080 端口, 以我所使用的 Spring Boot 为例, 仅仅是在 application.yml 中增加了两行配置而已.

server:
port: 8080
tomcat:
protocol_header: x-forwarded-proto
use-forward-headers: true
address: 127.0.0.1

证书申请/购买

在域名的基本信息页, 点击免费开启 SSL 证书, 输入相应的域名, 点击「申请」即可申请免费的 DV SSL 证书, 还需要做一些简单的信息补全等, 即可提交申请. 如果备案信息都齐全的话, 很快就可以验证成功, 在证书管理页面即可查看证书.

选择下载证书for Nginx, 证书一式两份, 后缀分别为 pemkey, 下载完上传到服务器.

域名映射

我选择为两个子域名申请证书, 同时将这两个域名映射到同一个IP.

Nginx 配置

首先, 需要把 http 都转发到 https, 需要使用 rewrite, 这样, 当访问 http://example.cn 会自动转发到 https://example.cn.

	server {
listen 80; # redirect to 443
server_name AAA.example.cn www.AAA.example.cn;
rewrite ^(.*)$ https://$host$1 permanent;
} server {
listen 80; # redirect to 443
server_name BBB.example.cn www.BBB.example.cn;
rewrite ^(.*)$ https://$host$1 permanent;
}

然后就是真正的 https 部分了, 虽然域名不同, 但都监听 443 端口, 但有着不同的 server_name, 这样当收到请求时就可以根据请求的 server_name 不同来转发到不同的服务.

而服务自身像往常一样只要继续监听 80908091 即可.

	server {
listen 443 ssl;
server_name AAA.example.cn www.AAA.example.cn; ssl_certificate "/home/yushan/demontf/2076603_AAA.example.cn.pem";
ssl_certificate_key "/home/yushan/demontf/2076603_AAA.example.cn.key"; location / {
proxy_pass http://127.0.0.1:8090;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect default;
}
} server {
listen 443 ssl; # redirect to https
server_name BBB.example.cn www.BBB.example.cn; ssl_certificate "/home/yushan/demontf/2005538_BBB.example.cn.pem";
ssl_certificate_key "/home/yushan/demontf/2005538_BBB.example.cn.key"; location / {
proxy_pass http://127.0.0.1:8091;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect default;
}
}

配置修改好之后, 需要重启 Nginx.

参考

Nginx 配置 HTTPS 服务器 | Aotu.io「凹凸实验室」

阿里云+Https+Nginx+SpringBoot | tt_study

Nginx 配置 HTTPS(多域名)的更多相关文章

  1. nginx配置https转发到tomcat(使用自签名的证书)

    一.使用openSSL生成自签名的证书 1.生成RSA私钥 命令:openssl genrsa -des3 -out server.key 1024 说明:生成rsa私钥,des3算法,1024强度, ...

  2. Nginx配置基于多域名、端口、IP的虚拟主机

    原文:https://www.cnblogs.com/ssgeek/p/9220922.html ------------------------------- Nginx配置基于多域名.端口.IP的 ...

  3. nginx 配置https并自签名证书

    2016-10-28 转载请注明出处:http://daodaoliang.com/ 作者: daodaoliang 版本: V1.0.1 邮箱: daodaoliang@yeah.net 参考链接: ...

  4. 购买https证书以及nginx配置https

    文章来源 运维公会:购买https证书以及nginx配置https 1.https的作用 https的全名是安全超文本传输协议,是在http的基础上增加了ssl加密协议.在信息传输的过程中,信息有可能 ...

  5. windwos下nginx 配置https并http强制跳转https

    windwos下nginx  配置https并http强制跳转https 一.首先配置证书文件 申请证书文件,这里就不做详细过程了,直接看证书文件结果. 这是两个证书的关键文件 打开ngxin下con ...

  6. nginx配置https及Android客户端访问自签名证书

    前一篇随笔通过keytool生成keystore并为tomcat配置https,这篇随笔记录如何给nginx配置https.如果nginx已配置https,则tomcat就不需要再配置https了.通 ...

  7. Nginx配置Https(详细、完整)

    Nginx配置Https(详细.完整) 原文链接:请支持原创 前置条件: 在配置https之前请确保下面的步骤已经完成 服务器已经安装nginx并且通过http可以正常访问 不会安装nginx的可以参 ...

  8. 【Nginx(五)】Nginx配置Https证书

    大致的流程如下 1.申请Https证书,绑定域名信息; 由于自己的服务器是腾讯云服务器, 这里就在腾讯云上申请SSL证书, 申请地址: https://console.cloud.tencent.co ...

  9. Nginx 配置 HTTPS 服务器

    Nginx 配置 HTTPS 服务器 Chrome 浏览器地址栏标志着 HTTPS 的绿色小锁头从心理层面上可以给用户专业安全的心理暗示,本文简单总结一下如何在 Nginx 配置 HTTPS 服务器, ...

随机推荐

  1. Python中的虚拟环境的使用

    1.安装virtualenv pip3 install virtualenv 2.创建目录 mkdir Myproject cd Myproject 3.创建独立运行环境-命名 virtualenv ...

  2. 联合主键SQL 联合索引

    联合主键索引 联合索引 ALTER TABLE [dbo].[Tb_Shop] ADD CONSTRAINT [shopno] UNIQUE NONCLUSTERED ( [ShopGid] ASC, ...

  3. Linux中搜索大于200M的文件

    Linux中清理磁盘空间时,经常需要找出大于200M的文件. 这个命令可以实现这个功能: find / -size +200M -exec du -h {} \;

  4. [LeetCode] 291. Word Pattern II 词语模式 II

    Given a pattern and a string str, find if str follows the same pattern. Here follow means a full mat ...

  5. 【ARM-Linux开发】ubuntu查看文件大小

    使用Linux命令df 和du,df 但是df只能查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力.du可以查看文件及文件夹的大小.所以基本上是两者配合使用. 一 df h参数, ...

  6. 用Postman做接口测试

    The higher your test coverage, the more flexible and bug-resistant your code will be, and the less t ...

  7. SpringBoot系列教程JPA之新增记录使用姿势

    SpringBoot系列教程JPA之新增记录使用姿势 上一篇文章介绍了如何快速的搭建一个JPA的项目环境,并给出了一个简单的演示demo,接下来我们开始业务教程,也就是我们常说的CURD,接下来进入第 ...

  8. qt creator的使用总结

    每一个不曾起舞的日子,都是对生命的辜负----------尼采 1.  HELP功能: 1)有时点击"HELP"之后,对应的页面里没有左侧的搜索栏.比较理想的状态是将左侧导航栏划分 ...

  9. LeetCode 856. 括号的分数(Score of Parentheses)

    856. 括号的分数 856. Score of Parentheses 题目描述 给定一个平衡括号字符串 S,按下述规则计算该字符串的分数: () 得 1 分. AB 得 A + B 分,其中 A ...

  10. liunx mysql数据库目录迁移

    1.查看mysql安装目录 从目录etc/my.cnf中查看安装目录 2.进入mysql目录,停止mysql服务 命令: cd usr/local/mysql 命令:service mysql sto ...