90 lines
2.6 KiB
Plaintext
90 lines
2.6 KiB
Plaintext
# 游戏客户端nginx配置文件
|
||
# 将此文件复制到 /usr/local/openresty/nginx/conf/conf.d/mssg-client.conf
|
||
# 或 /usr/local/openresty/nginx/conf/default/mssg-client.conf
|
||
|
||
# 上游服务器配置(可选,如果使用负载均衡)
|
||
# upstream game_server {
|
||
# server 127.0.0.1:8004;
|
||
# }
|
||
|
||
# upstream api_server {
|
||
# server 127.0.0.1:8088;
|
||
# }
|
||
|
||
server {
|
||
# 使用6060端口,避免备案拦截
|
||
listen 6060;
|
||
server_name 103.236.81.216;
|
||
|
||
# 客户端静态文件根目录
|
||
root /root/mssg/slgclient/webdesktop;
|
||
index index.html;
|
||
|
||
# 日志配置
|
||
access_log /var/log/nginx/mssg_client_access.log;
|
||
error_log /var/log/nginx/mssg_client_error.log;
|
||
|
||
# WebSocket代理 - 游戏服务器(必须在根location之前)
|
||
location /ws {
|
||
proxy_pass http://127.0.0.1:8004;
|
||
proxy_http_version 1.1;
|
||
|
||
# WebSocket升级头
|
||
proxy_set_header Upgrade $http_upgrade;
|
||
proxy_set_header Connection "upgrade";
|
||
|
||
# 传递原始请求信息
|
||
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;
|
||
|
||
# WebSocket超时设置
|
||
proxy_read_timeout 3600s;
|
||
proxy_send_timeout 3600s;
|
||
}
|
||
|
||
# HTTP API代理 - 后端API服务(必须在根location之前)
|
||
location /api/ {
|
||
proxy_pass http://127.0.0.1:8088/;
|
||
proxy_http_version 1.1;
|
||
|
||
# 传递原始请求信息
|
||
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;
|
||
|
||
# CORS配置(如果需要跨域)
|
||
add_header Access-Control-Allow-Origin *;
|
||
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
||
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
|
||
|
||
# 处理OPTIONS预检请求
|
||
if ($request_method = 'OPTIONS') {
|
||
return 204;
|
||
}
|
||
}
|
||
|
||
# 静态文件缓存配置(必须在根location之前)
|
||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|json|plist)$ {
|
||
expires 30d;
|
||
add_header Cache-Control "public, immutable";
|
||
try_files $uri =404;
|
||
}
|
||
|
||
# 主页面和SPA路由支持(必须放在最后)
|
||
location / {
|
||
try_files $uri $uri/ /index.html;
|
||
index index.html;
|
||
}
|
||
|
||
# 禁止访问隐藏文件
|
||
location ~ /\. {
|
||
deny all;
|
||
access_log off;
|
||
log_not_found off;
|
||
}
|
||
}
|
||
|