更新 Nginx 配置,使用自定义 404 页面并优化未命中路径处理逻辑
This commit is contained in:
18
ngnix.conf
18
ngnix.conf
@@ -1,4 +1,4 @@
|
||||
# Nginx 静态文件服务 + 前端入口兜底
|
||||
# Nginx 静态文件服务 + 自定义 404 页面
|
||||
|
||||
# HTTP 重定向到 HTTPS
|
||||
server {
|
||||
@@ -19,8 +19,12 @@ server {
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||
|
||||
# 域名下任意未命中路径都不要落到 nginx 默认 404
|
||||
error_page 404 = /web/index.html;
|
||||
# 使用项目自定义静态 404 页面,保持 nginx 返回 404 状态码
|
||||
error_page 404 /404.html;
|
||||
|
||||
location = /404.html {
|
||||
internal;
|
||||
}
|
||||
|
||||
# 根路径默认进入网页端
|
||||
location = / {
|
||||
@@ -39,17 +43,17 @@ server {
|
||||
# 网页端(public/web/index.html -> dist/web/index.html)
|
||||
location /web/ {
|
||||
alias /usr/share/nginx/html/web/;
|
||||
try_files $uri $uri/ /web/index.html;
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
|
||||
# 后台管理端(dist/index.html,前缀 /sys/)
|
||||
location /sys/ {
|
||||
alias /usr/share/nginx/html/;
|
||||
try_files $uri $uri/ /sys/index.html;
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
|
||||
# 其他任意路径统一兜底到网页端入口,避免出现 nginx 404 页面
|
||||
# 其他静态资源或任意路径,未命中时统一交给 nginx 404,再由自定义 404 页面展示
|
||||
location / {
|
||||
try_files $uri $uri/ /web/index.html;
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user