22301111 | 4511d21 | 2025-06-05 18:36:11 +0800 | [diff] [blame] | 1 | server { |
| 2 | listen 80; |
| 3 | server_name localhost team11.10813352.xyz; |
| 4 | |
| 5 | # 前端请求(React 静态资源) |
| 6 | location / { |
| 7 | root /usr/share/nginx/html; # React 构建文件默认位置 |
| 8 | index index.html; |
| 9 | try_files $uri $uri/ /index.html; # 支持前端路由 |
| 10 | } |
| 11 | |
| 12 | # 后端 API 请求 |
| 13 | location /echo { |
| 14 | proxy_pass http://backend:5011; # 转发到后端容器 |
| 15 | proxy_set_header Host $host; |
| 16 | proxy_set_header X-Real-IP $remote_addr; |
| 17 | } |
22301111 | 8c88786 | 2025-06-05 20:57:18 +0800 | [diff] [blame] | 18 | |
| 19 | # 静态图片资源 |
| 20 | # 方案1:直接通过Nginx提供静态文件 |
| 21 | location /uploads/ { |
| 22 | alias /usr/share/nginx/html/uploads/; |
| 23 | expires 30d; |
| 24 | } |
| 25 | # 方案2:代理到后端服务(如果后端需要处理文件访问逻辑) |
| 26 | # location /uploads/ { |
| 27 | # proxy_pass http://backend:5011; |
| 28 | # proxy_set_header Host $host; |
| 29 | # } |
22301111 | 4511d21 | 2025-06-05 18:36:11 +0800 | [diff] [blame] | 30 | } |