Commit a0a85ff7 by zhangxingmin

push

parent 73a93005
...@@ -8,16 +8,30 @@ server { ...@@ -8,16 +8,30 @@ server {
listen 2668; listen 2668;
server_name localhost; server_name localhost;
# 处理前端静态资源(Vue应用) root /usr/share/nginx/html;
location / { index index.html;
root /usr/share/nginx/html;
index index.html; # 静态资源处理 - 必须放在最前面
try_files $uri $uri/ /index.html; # 处理Vue路由history模式 location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|map)$ {
# 确保静态资源有正确的过期时间和缓存头
expires 1y;
add_header Cache-Control "public, immutable";
# 为静态资源添加CORS头 # 为静态资源添加CORS头
add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization' always; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization' always;
# 处理OPTIONS请求(CORS预检)
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Length' 0;
add_header 'Content-Type' 'text/plain; charset=UTF-8';
return 204;
}
} }
# 代理API请求到网关服务 # 代理API请求到网关服务
...@@ -64,4 +78,14 @@ server { ...@@ -64,4 +78,14 @@ server {
return 200 "healthy\n"; return 200 "healthy\n";
add_header Content-Type text/plain; add_header Content-Type text/plain;
} }
# 前端路由处理 - 放在最后,作为兜底规则
location / {
try_files $uri $uri/ /index.html; # 处理Vue路由history模式
# 为页面添加CORS头
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization' always;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment