From ffaf04982a50d87d88be7e57c5972456f16e11db Mon Sep 17 00:00:00 2001 From: 2910410219 <2910410219@qq.com> Date: Tue, 9 Jun 2026 13:20:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Nginx=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8=E8=87=AA=E5=AE=9A=E4=B9=89=20404=20?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=B9=B6=E4=BC=98=E5=8C=96=E6=9C=AA=E5=91=BD?= =?UTF-8?q?=E4=B8=AD=E8=B7=AF=E5=BE=84=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ngnix.conf | 18 ++-- public/404.html | 212 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+), 7 deletions(-) create mode 100644 public/404.html diff --git a/ngnix.conf b/ngnix.conf index 3e4061e..50cb987 100644 --- a/ngnix.conf +++ b/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; } } diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..004ab0d --- /dev/null +++ b/public/404.html @@ -0,0 +1,212 @@ + + +
+ + +