平常开发要求比较低, 依然在用 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. 算法名称 Alias Method

    public class AliasMethod { /* The probability and alias tables. */ private int[] _alias; private dou ...

  2. osg::Node位置移动

    osg::Node节点移动的时候,可以使用osg::Matrix::translate  来完成 osg::Matrix::translate中的参数是  当前位置到目标位置需要改变的值,所以,传递参 ...

  3. 使用协方差矩阵的特征向量PCA来处理数据降维

    取2维特征,方便图形展示 import matplotlib.pyplot as plt from sklearn.decomposition import PCA from sklearn.data ...

  4. [LeetCode] 167. Two Sum II - Input array is sorted 两数和 II - 输入是有序的数组

    Given an array of integers that is already sorted in ascending order, find two numbers such that the ...

  5. [LeetCode] 682. Baseball Game 棒球游戏

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

  6. 分享一下我的个人微信小程序

    分享一下我的个人微信小程序 1.有我平时整理的一些小程序相关的技术,供大家参考. 2.有几个好玩的例子 有问题可以一起参考

  7. 第07组 Beta冲刺(2/4)

    队名:秃头小队 组长博客 作业博客 组长徐俊杰 过去两天完成的任务:学习了很多东西 Github签入记录 接下来的计划:继续学习 还剩下哪些任务:后端部分 燃尽图 遇到的困难:自己太菜了 收获和疑问: ...

  8. 利用js来画图形(例如:条状图,圆饼图等)

    背景:java开发的过程中,需要对数据进行可视化,这样方便客户理解此时的数据状态 语言:java,js,window7,echarts包文件 sample的例子下面的参照 https://www.ec ...

  9. python实践项目四:猜数字游戏

    题目要求:在1-20中随机生成一个数字,你来猜,只有6次机会. 举例一: #!/usr/bin/python # -*- coding: UTF-8 -*- import random secretN ...

  10. [转帖]Chrome用户请尽快更新:谷歌发现两个严重的零日漏洞

    Chrome用户请尽快更新:谷歌发现两个严重的零日漏洞 https://news.cnblogs.com/n/647075/ 强烈建议:Chrome 用户请尽快升级浏览器!在谷歌今天发布的紧急补丁程序 ...