server { | |
listen 80; | |
server_name localhost team11.10813352.xyz; | |
# 前端请求(React 静态资源) | |
location / { | |
root /usr/share/nginx/html; # React 构建文件默认位置 | |
index index.html; | |
try_files $uri $uri/ /index.html; # 支持前端路由 | |
} | |
# 后端 API 请求 | |
location /echo { | |
proxy_pass http://backend:5011; # 转发到后端容器 | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
} | |
# 静态图片资源 | |
# 方案1:直接通过Nginx提供静态文件 | |
location /uploads/ { | |
alias /usr/share/nginx/html/uploads/; | |
expires 30d; | |
} | |
# 方案2:代理到后端服务(如果后端需要处理文件访问逻辑) | |
# location /uploads/ { | |
# proxy_pass http://backend:5011; | |
# proxy_set_header Host $host; | |
# } | |
} |