feat: 更新 Nginx 配置以支持新的网页和后台管理端路径
- 修改根路径重定向至网页端的 index.html。 - 新增网页端和后台管理端的路径配置,确保静态资源正确加载。 - 优化了静态文件查找和代理逻辑,提升了请求处理效率。
This commit is contained in:
37
ngnix.conf
37
ngnix.conf
@@ -1,20 +1,8 @@
|
|||||||
# Nginx 静态文件服务 + 智能代理
|
# Nginx 静态文件服务 + 智能代理
|
||||||
|
|
||||||
server {
|
server {
|
||||||
# 静态资源根目录
|
# 静态资源根目录(dist)
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
|
|
||||||
# 前端资源路径别名(/sys/ -> /)
|
|
||||||
location /sys/ {
|
|
||||||
alias /usr/share/nginx/html/;
|
|
||||||
try_files $uri $uri/ =404;
|
|
||||||
}
|
|
||||||
|
|
||||||
# 根路径固定进入前端,避免落到后端登录页
|
|
||||||
location = / {
|
|
||||||
return 302 /sys/;
|
|
||||||
}
|
|
||||||
|
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
# SSL 配置
|
# SSL 配置
|
||||||
@@ -24,6 +12,23 @@ server {
|
|||||||
ssl_protocols TLSv1.2 TLSv1.3;
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
ssl_ciphers HIGH:!aNULL:!MD5;
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||||
|
|
||||||
|
# 根路径默认进入网页端
|
||||||
|
location = / {
|
||||||
|
return 302 /web/index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 网页端(public/web/index.html -> dist/web/index.html)
|
||||||
|
location /web/ {
|
||||||
|
alias /usr/share/nginx/html/web/;
|
||||||
|
try_files $uri $uri/ /web/index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 后台管理端(dist/index.html,前缀 /sys/)
|
||||||
|
location /sys/ {
|
||||||
|
alias /usr/share/nginx/html/;
|
||||||
|
try_files $uri $uri/ /sys/index.html;
|
||||||
|
}
|
||||||
|
|
||||||
# 1. 先尝试作为静态文件查找
|
# 1. 先尝试作为静态文件查找
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ @proxy;
|
try_files $uri $uri/ @proxy;
|
||||||
@@ -31,12 +36,12 @@ server {
|
|||||||
|
|
||||||
# 2. 无法找到的请求(API路径)代理到后端
|
# 2. 无法找到的请求(API路径)代理到后端
|
||||||
location @proxy {
|
location @proxy {
|
||||||
# 判断URI最后一段是否有扩展名
|
# 判断 URI 最后一段是否有扩展名
|
||||||
# 有扩展名返回404,无扩展名则代理
|
# 有扩展名返回 404,无扩展名则代理
|
||||||
if ($uri ~ \.[^./]+$) {
|
if ($uri ~ \.[^./]+$) {
|
||||||
return 404;
|
return 404;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy_pass http://116.204.74.41:8000;
|
proxy_pass http://116.204.74.41:8000;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
|||||||
Reference in New Issue
Block a user