使用 Nginx 将部署多个子域名&http服务重定向到https服务

首先在阿里云解析对应的子域名

  1. 打开自己的域名解析
  2. 点击添加记录

然后在nginx的配置文件下新增以下内容

nginx 复制代码
# ssl证书地址,是你自己服务器上证书存放的地址
ssl_certificate      /ssl/fullchain.cer; 
ssl_certificate_key  /ssl/cert.key;

#请按照以下协议配置
ssl_protocols TLSv1.2 TLSv1.3; 

#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; 

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;

#表示优先使用服务端加密套件。默认开启
ssl_prefer_server_ciphers on;

# http 重定向到 https
server {
    listen       80;
    server_name  _;
    return       301 https://$host$request_uri;
}

server {
    listen       443 ssl;
    server_name  www.1024bugs.top;
    # 对应项目1地址
    root         /www/web/dist;
    index        index.html index.htm;
}

server {
    listen       443 ssl;
    server_name  h5.1024bugs.top;
    # 对应项目2的地址
    root         /www/h5/h5-vant;
    index        index.html index.htm;
}

server {
    listen       443 ssl;
    server_name  web.oposet.com;
	# 对应项目三的地址
    root         /www/h5/h5-varlet;
    index        index.html index.htm;
}

配置好重载nginx, 即可生效

shell 复制代码
nginx -s reload
相关推荐
普普通通的南瓜9 小时前
一年期免费IP证书,为公网IP地址提供HTTPS加密
网络·网络协议·tcp/ip·安全·http·金融·https
青果全球http13 小时前
HTTP代理原理揭秘:如何实现高效数据中转?
网络·网络协议·http
im_AMBER13 小时前
weather-app开发手记 01 HTTP请求基础 | Axios GET 请求
笔记·网络协议·学习·计算机网络·http·axios
打不了嗝 ᥬ᭄16 小时前
【Linux】多路转接 Select , Poll和Epoll
linux·网络·c++·网络协议·http
全栈工程师修炼指南16 小时前
Nginx | 负载均衡策略:一致性哈希算法实践
运维·算法·nginx·负载均衡·哈希算法
街灯L18 小时前
【Ubuntu】安装配置nginx文件版
服务器·nginx·ubuntu
HIT_Weston18 小时前
53、【Ubuntu】【Gitlab】拉出内网 Web 服务:http.server 单/多线程分析(五)
网络协议·http·gitlab
阿巴~阿巴~18 小时前
HTTP服务器实现请求解析与响应构建:从基础架构到动态交互
服务器·网络·网络协议·http·交互·请求解析·响应构建
黛琳ghz18 小时前
极速云原生:openEuler之Redis与Nginx部署性能实战
redis·nginx·云原生·操作系统·压力测试·openeuler·服务器部署
HIT_Weston19 小时前
52、【Ubuntu】【Gitlab】拉出内网 Web 服务:http.server 单/多线程分析(四)
ubuntu·http·gitlab