config: 更新 nginx 配置为域名访问,添加 HTTPS SSL 支持
This commit is contained in:
+40
-39
@@ -1,27 +1,43 @@
|
|||||||
# Emotion Museum 前端应用 Nginx 配置
|
# Emotion Museum - 域名部署配置
|
||||||
# 配置路径: /www/server/panel/vhost/nginx/emotion-museum.conf
|
# 域名:lifescript.happylifeos.com
|
||||||
|
# 配置路径:/etc/nginx/sites-available/lifescript.happylifeos.com.conf
|
||||||
|
|
||||||
|
# HTTP 服务器 - 强制跳转 HTTPS
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name 101.200.208.45;
|
server_name lifescript.happylifeos.com;
|
||||||
|
|
||||||
# 根路径不提供站点,避免跳转或兜底到其他 server
|
# 强制跳转 HTTPS
|
||||||
location = / {
|
return 301 https://$server_name$request_uri;
|
||||||
return 404;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
# 前端应用路径
|
# HTTPS 服务器
|
||||||
location /emotion-museum/ {
|
server {
|
||||||
|
listen 443 ssl http2;
|
||||||
|
server_name lifescript.happylifeos.com;
|
||||||
|
|
||||||
|
# SSL 证书配置
|
||||||
|
ssl_certificate /etc/letsencrypt/live/lifescript.happylifeos.com/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/lifescript.happylifeos.com/privkey.pem;
|
||||||
|
|
||||||
|
# SSL 优化配置
|
||||||
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
|
||||||
|
ssl_session_cache shared:SSL:10m;
|
||||||
|
ssl_session_timeout 10m;
|
||||||
|
|
||||||
|
# HSTS (可选,生产环境建议开启)
|
||||||
|
# add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||||
|
|
||||||
|
# 根路径 - 用户前端应用
|
||||||
|
location / {
|
||||||
alias /data/www/emotion-museum/;
|
alias /data/www/emotion-museum/;
|
||||||
|
|
||||||
# 启用目录索引(可选)
|
|
||||||
autoindex off;
|
autoindex off;
|
||||||
|
|
||||||
# 处理 Vue Router 的 history 模式
|
# 处理 Vue Router 的 history 模式
|
||||||
# 所有非文件请求都重定向到 index.html
|
try_files $uri $uri/ /index.html;
|
||||||
try_files $uri $uri/ /emotion-museum/index.html;
|
|
||||||
|
|
||||||
# 设置缓存策略
|
|
||||||
# HTML 文件不缓存
|
# HTML 文件不缓存
|
||||||
location ~ \.html?$ {
|
location ~ \.html?$ {
|
||||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||||
@@ -36,23 +52,14 @@ server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# 处理不带末尾斜杠的 /emotion-museum 请求
|
|
||||||
location = /emotion-museum {
|
|
||||||
rewrite ^(.*)$ $1/ permanent;
|
|
||||||
}
|
|
||||||
|
|
||||||
# 管理后台应用路径
|
# 管理后台应用路径
|
||||||
location /emotion-museum-admin/ {
|
location /emotion-museum-admin/ {
|
||||||
alias /data/www/emotion-museum-admin/;
|
alias /data/www/emotion-museum-admin/;
|
||||||
|
|
||||||
# 启用目录索引(可选)
|
|
||||||
autoindex off;
|
autoindex off;
|
||||||
|
|
||||||
# 处理 Vue Router 的 history 模式
|
# 处理 Vue Router 的 history 模式
|
||||||
# 所有非文件请求都重定向到 index.html
|
|
||||||
try_files $uri $uri/ /emotion-museum-admin/index.html;
|
try_files $uri $uri/ /emotion-museum-admin/index.html;
|
||||||
|
|
||||||
# 设置缓存策略
|
|
||||||
# HTML 文件不缓存
|
# HTML 文件不缓存
|
||||||
location ~ \.html?$ {
|
location ~ \.html?$ {
|
||||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||||
@@ -72,18 +79,14 @@ server {
|
|||||||
rewrite ^(.*)$ $1/ permanent;
|
rewrite ^(.*)$ $1/ permanent;
|
||||||
}
|
}
|
||||||
|
|
||||||
# 体验前端应用路径 (course-web)
|
# Life-Script 应用路径
|
||||||
location /course-of-life/ {
|
location /life-script/ {
|
||||||
alias /data/www/course-of-life/;
|
alias /data/www/life-script/;
|
||||||
|
|
||||||
# 启用目录索引(可选)
|
|
||||||
autoindex off;
|
autoindex off;
|
||||||
|
|
||||||
# 处理 SPA 的 history 模式 (React Router)
|
# 处理 React Router 的 history 模式
|
||||||
# 所有非文件请求都重定向到 index.html
|
try_files $uri $uri/ /life-script/index.html;
|
||||||
try_files $uri $uri/ /course-of-life/index.html;
|
|
||||||
|
|
||||||
# 设置缓存策略
|
|
||||||
# HTML 文件不缓存
|
# HTML 文件不缓存
|
||||||
location ~ \.html?$ {
|
location ~ \.html?$ {
|
||||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||||
@@ -98,11 +101,9 @@ server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# 处理不带末尾斜杠的 /course-of-life 请求
|
# 处理不带末尾斜杠的 /life-script 请求
|
||||||
location = /course-of-life {
|
location = /life-script {
|
||||||
# 不进行 301/302 外部跳转:内部改写到 /course-of-life/ 交给下方 SPA location 处理
|
rewrite ^ /life-script/ last;
|
||||||
# 这样 URL 仍是 /course-of-life,但返回内容与 /course-of-life/ 完全一致(且不会触发“下载”)
|
|
||||||
rewrite ^ /course-of-life/ last;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# 后端 API 代理
|
# 后端 API 代理
|
||||||
@@ -150,6 +151,6 @@ server {
|
|||||||
log_not_found off;
|
log_not_found off;
|
||||||
}
|
}
|
||||||
|
|
||||||
access_log /www/wwwlogs/access.log;
|
access_log /var/log/nginx/lifescript_access.log;
|
||||||
|
error_log /var/log/nginx/lifescript_error.log;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user