2025-03-30 22:11:50 +08:00
|
|
|
server {
|
|
|
|
|
listen 8080;
|
|
|
|
|
server_name localhost;
|
|
|
|
|
|
|
|
|
|
# gzip 配置
|
|
|
|
|
gzip on;
|
|
|
|
|
gzip_min_length 1k;
|
|
|
|
|
gzip_comp_level 6;
|
|
|
|
|
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
|
|
|
|
|
gzip_vary on;
|
|
|
|
|
gzip_proxied any;
|
|
|
|
|
|
2025-04-14 14:27:19 +08:00
|
|
|
root /usr/share/nginx/html/react-web;
|
2025-03-30 22:11:50 +08:00
|
|
|
index index.html;
|
|
|
|
|
|
2025-04-09 16:21:39 +08:00
|
|
|
# 支持 history 路由
|
2025-03-30 22:11:50 +08:00
|
|
|
location / {
|
|
|
|
|
try_files $uri $uri/ /index.html;
|
2025-04-01 08:58:58 +08:00
|
|
|
|
|
|
|
|
# 添加必要的跨域和缓存控制头
|
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
2025-05-12 10:15:53 +08:00
|
|
|
# 调整缓存策略,例如对于静态资源可以缓存
|
|
|
|
|
location ~* \.(css|js|svg|png|jpg|jpeg)$ {
|
|
|
|
|
expires 365d;
|
|
|
|
|
}
|
2025-04-01 08:58:58 +08:00
|
|
|
|
|
|
|
|
# 添加安全相关头
|
|
|
|
|
add_header X-Frame-Options SAMEORIGIN;
|
|
|
|
|
add_header X-Content-Type-Options nosniff;
|
|
|
|
|
add_header X-XSS-Protection "1; mode=block";
|
2025-03-30 22:11:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# API-UAA 服务代理
|
|
|
|
|
location /api-uaa/ {
|
2025-04-09 16:20:49 +08:00
|
|
|
proxy_pass http://119.45.169.13:9900/api-uaa/;
|
2025-03-30 22:11:50 +08:00
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
|
2025-04-09 16:20:49 +08:00
|
|
|
# 确保 Authorization 头可以传递
|
|
|
|
|
proxy_set_header Authorization $http_authorization;
|
|
|
|
|
proxy_pass_header Authorization;
|
2025-05-12 10:15:53 +08:00
|
|
|
|
|
|
|
|
# 处理 OPTIONS 请求
|
|
|
|
|
if ($request_method = 'OPTIONS') {
|
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
|
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
|
|
|
|
|
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
|
|
|
|
return 204;
|
|
|
|
|
}
|
2025-04-09 16:20:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 用户服务代理
|
|
|
|
|
location /api-user/ {
|
|
|
|
|
proxy_pass http://119.45.169.13:9900/api-user/;
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
2025-04-01 08:58:58 +08:00
|
|
|
|
2025-04-09 16:20:49 +08:00
|
|
|
# 确保 Authorization 头可以传递
|
|
|
|
|
proxy_set_header Authorization $http_authorization;
|
|
|
|
|
proxy_pass_header Authorization;
|
2025-05-12 10:15:53 +08:00
|
|
|
|
|
|
|
|
# 处理 OPTIONS 请求
|
|
|
|
|
if ($request_method = 'OPTIONS') {
|
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
|
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
|
|
|
|
|
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
|
|
|
|
return 204;
|
|
|
|
|
}
|
2025-03-30 22:11:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 其他 API 服务代理(如果需要)
|
|
|
|
|
location /api/ {
|
|
|
|
|
proxy_pass http://119.45.169.13:9900/; # 替换为实际的后端地址
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
|
|
|
|
|
# 添加跨域头
|
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
|
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
|
|
|
|
|
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
|
|
|
|
|
|
|
|
|
# 处理 OPTIONS 请求
|
|
|
|
|
if ($request_method = 'OPTIONS') {
|
|
|
|
|
return 204;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-14 14:27:19 +08:00
|
|
|
|
|
|
|
|
# API 代理配置
|
|
|
|
|
location /api-order/ {
|
|
|
|
|
proxy_pass http://119.45.169.13:9900/api-order/; # 替换为您的后端API地址
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
2025-05-12 10:15:53 +08:00
|
|
|
|
|
|
|
|
# 处理 OPTIONS 请求
|
|
|
|
|
if ($request_method = 'OPTIONS') {
|
|
|
|
|
add_header Access-Control-Allow-Origin *;
|
|
|
|
|
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
|
|
|
|
|
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
|
|
|
|
return 204;
|
|
|
|
|
}
|
2025-04-14 14:27:19 +08:00
|
|
|
}
|
2025-03-30 22:11:50 +08:00
|
|
|
}
|