使用 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
相关推荐
en-route9 分钟前
Http请求中的特殊字符
spring·http
游戏开发爱好者810 小时前
iOS App 电池消耗管理与优化 提升用户体验的完整指南
android·ios·小程序·https·uni-app·iphone·webview
代码搬运媛10 小时前
HTTP REST API、WebSocket、 gRPC 和 GraphQL 应用场景和底层实现
websocket·http·graphql
蔡不菜和他的uU们14 小时前
LAMP迁移LNMP Nginx多站点配置全流程
运维·nginx
一眼万年0414 小时前
Nginx Master-Worker 进程间的共享内存是怎么做到通用还高效的?
后端·nginx·面试
用户697793063425314 小时前
什么?2025年了发版后还要手动清浏览器缓存?
前端·nginx
不认输的西瓜16 小时前
前端网络知识——HTTP和HTTPS
http·https
Jiude16 小时前
如何使用 Certbot 为域名配置永久免费的 HTTPS 证书
后端·nginx·https
2501_9159184118 小时前
iOS 性能监控工具全解析 选择合适的调试方案提升 App 性能
android·ios·小程序·https·uni-app·iphone·webview
Britz_Kevin21 小时前
从零开始的云计算生活——番外3,LVS+KeepAlived+Nginx高可用实现方案
nginx·云计算·生活·lvs·#keepalived