44 lines
1.2 KiB
Nginx Configuration File
44 lines
1.2 KiB
Nginx Configuration File
server {
|
||
listen 80;
|
||
server_name localhost;
|
||
|
||
# 配置静态资源服务
|
||
location / {
|
||
root /usr/share/nginx/html;
|
||
index index.html;
|
||
# 处理前端路由(SPA模式)
|
||
try_files $uri $uri/ /index.html;
|
||
}
|
||
|
||
# 配置API反向代理到后端服务
|
||
location /api/ {
|
||
proxy_pass http://backend:3000/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;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
|
||
# 增加超时配置
|
||
proxy_connect_timeout 5s;
|
||
proxy_read_timeout 60s;
|
||
proxy_send_timeout 60s;
|
||
}
|
||
|
||
# 配置游戏API代理(如果需要)
|
||
location /game-api/ {
|
||
proxy_pass http://backend:3000/game-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;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
|
||
# 增加超时配置
|
||
proxy_connect_timeout 5s;
|
||
proxy_read_timeout 60s;
|
||
proxy_send_timeout 60s;
|
||
}
|
||
|
||
# 配置404页面
|
||
error_page 404 /index.html;
|
||
}
|