使用 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
相关推荐
牛奶1 天前
HTTPS你不知道的事
前端·https·浏览器
喵个咪3 天前
Go-Wind HTTP 服务器从入门到精通
后端·http·go
AlfredZhao5 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
Goodbye8 天前
大模型无状态架构:从 HTTP 协议到 Harness AI 工程的深度解析
http
Avan_菜菜9 天前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
ping某13 天前
为什么 Nginx 明明监听了 80,转发后端时却用了 4xxxx 端口?
后端·nginx
霜落长河15 天前
抛弃TCP改用UDP,HTTP3怎么了?
http
程序员mine15 天前
HTTPS-TLS加密与证书完全指南(中)
网络协议·https·ssl
之歆15 天前
现代 HTTP 客户端深度解析:Fetch 与 Axios
chrome·网络协议·http
難釋懷16 天前
Nginx反向代理中的容错机制
运维·nginx