Files
OpenFrontIO/nginx.conf
T
2025-02-27 10:45:30 -08:00

108 lines
2.7 KiB
Nginx Configuration File

resolver 127.0.0.11 valid=30s;
# Access log format with minimal information
log_format minimal '$remote_addr - [$time_local] "$request" $status';
map $uri $port {
~^/w0/ 3001;
~^/w1/ 3002;
~^/w2/ 3003;
~^/w3/ 3004;
~^/w4/ 3005;
~^/w5/ 3006;
~^/w6/ 3007;
~^/w7/ 3008;
~^/w8/ 3009;
~^/w9/ 3010;
~^/w10/ 3011;
~^/w11/ 3012;
~^/w12/ 3013;
~^/w13/ 3014;
~^/w14/ 3015;
default 3000;
}
# Don't strip the path for WebSocket connections
map $http_upgrade $strip_path {
default 1;
websocket 0;
}
map $uri $uri_path {
# Only strip path if not a WebSocket request
~^/w\d+(/.*)?$ $1;
default $uri;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
# Reduced logging
access_log /var/log/nginx/access.log minimal;
error_log /var/log/nginx/error.log error;
# Disable logging for common requests
location = /favicon.ico {
access_log off;
log_not_found off;
return 204;
}
# WebSocket timeout settings
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
proxy_send_timeout 300s;
# Special location block just for WebSocket connections
location ~* ^/w\d+$ {
set $ws_port 0;
if ($uri ~* ^/w0) {
set $ws_port 3001;
}
if ($uri ~* ^/w1) {
set $ws_port 3002;
}
if ($uri ~* ^/w2) {
set $ws_port 3003;
}
if ($uri ~* ^/w3) {
set $ws_port 3004;
}
if ($uri ~* ^/w4) {
set $ws_port 3005;
}
# Add more conditions for other worker paths
proxy_pass http://game-server:$ws_port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $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;
proxy_buffering off;
}
# Regular location for all other requests
location / {
set $upstream_endpoint game-server:$port;
proxy_pass http://$upstream_endpoint$uri_path;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $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;
proxy_buffering off;
}
}