Nginx 多个域名解析到同一个服务器
域名证书绑定参照:nginx 发布网站通过域名访问,后端接口反向代理 - AutumnSilence - 博客园 (cnblogs.com)
1、域名解析到服务器上
2、修改nginx 配置文件
定义两个 server,监听443端口, 修改server_name 绑定的值
server {
listen 443 ssl;
# 你的域名
server_name www.xxxxxx.cn;
# 你的证书 crt对应的是公钥 key对应的是私钥
ssl_certificate XXXXX.pem;
ssl_certificate_key XXXXXX.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# 访问根路径跳转页面
# 如:https://xxxx.com/
location / {
root C:/dist; #C:/ArchiveV9/wangluo/vue/dist; #C:/dist;
index index.html index.htm;
add_header Content-Security-Policy upgrade-insecure-requests;
}
# 访问/api的时候代理到服务器端部署的后端服务
# 如:https://xxxx.com/api
location /api {
proxy_pass http://47.101.202.57:3031/; #http://47.101.202.57:5003;
}
}
server {
listen 443 ssl;
# 你的域名
server_name www.xxxxx.com;
# 你的证书 crt对应的是公钥 key对应的是私钥
ssl_certificate XXXXX.pem;
ssl_certificate_key XXXXX.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# 访问根路径跳转页面
# 如:https://xxxx.com/
location / {
root C:/XXXX/XXXX;
index index.html index.htm;
add_header Content-Security-Policy upgrade-insecure-requests;
}
}