blob: 7dd34cc41b79416979dda371d9429ec2b838602a [file] [log] [blame]
Xing Jinwen11496472025-06-06 13:16:26 +08001server {
2 listen 80;
3 server_name localhost;
4
5 # 前端静态文件
6 location / {
7 root /usr/share/nginx/html;
8 index index.html index.htm;
9 try_files $uri $uri/ /index.html;
10 }
11
12 # API 请求代理到后端
13 location /api {
14 proxy_pass http://backend:8080;
15 proxy_http_version 1.1;
16 proxy_set_header Upgrade $http_upgrade;
17 proxy_set_header Connection 'upgrade';
18 proxy_set_header Host $host;
19 proxy_set_header X-Real-IP $remote_addr;
20 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
21 proxy_set_header X-Forwarded-Proto $scheme;
22 proxy_cache_bypass $http_upgrade;
23
24 # 处理 CORS
25 add_header 'Access-Control-Allow-Origin' '*';
26 add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
27 add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,sapling-token';
28
29 if ($request_method = 'OPTIONS') {
30 return 204;
31 }
32 }
33
34 # 健康检查
35 location /health {
36 access_log off;
37 return 200 "healthy\n";
38 }
39}