我在中东拥有一个游戏服务器(反恐精英 2)。我正在尝试为它设置一个网络面板,该面板托管在欧洲的 ubuntu 22 VPS 上。该网站有一个工具,允许使用源 RCON 协议从网站在游戏服务器上运行远程命令。
该网站使用 PHP(Laravel)。当我尝试使用网站上的 RCON 控制台运行命令时,出现 Nginx 504 网关超时。
Nginx 日志显示以下内容:
2024/12/25 22:21:34 [error] 1431#1431: *2081 upstream timed out (110: Unknown error) while reading response header from upstream, client: 88.196.213.143, server: some.domain.com, request: "GET /servers/1/players HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock", host: "some.domain.com", referrer: "https://some.domain.com/"
起初,我以为欧洲 VPS 和我的游戏服务器之间可能存在连接问题,所以我在我的欧洲 VPS 上安装了 rcon-cli,使用它,我能够成功连接到游戏服务器。结果,我发现该问题仅与 PHP RCON 工具有关。
由于许多人都在使用这个网站面板,并且没有遇到任何问题,所以我怀疑代码也存在问题。我唯一想到的是我的 Nginx 配置。
这是我的 Nginx site.conf:
server {
listen 80;
listen [::]:80;
listen 443 ssl;
server_name some.domain.com;
root /var/www/html/aim1/public; ##<----THIS IS THE ACTUAL PATH
ssl_certificate /root/cert/some.domain.com/fullchain.pem;
ssl_certificate_key /root/cert/some.domain.com/privkey.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_hide_header X-Powered-By;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
这是我的 fastcgi.conf:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
最后,这是我的 nginx.conf 文件:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
谁能帮助我摆脱这个 Nginx 错误?