0

I own a game server (counter strike 2) in the middle east . I'm trying to set up a web panel for it which is hosted in Europe on an ubuntu 22 VPS . This website has a tool that allows remote commands to be run on the game server from the website using the source RCON protocol .

The website uses PHP (Laravel). When I try to use the RCON console on the website to run commands , I get Nginx 504 gateway time-out .

The Nginx log shows the following :

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/" 

At first , I thought maybe there is a connection issue between the Europe VPS and my game server so I installed rcon-cli on my Europe VPS and using that , I was able to successfully connect to game server . As a result , I figured the issue is only related to PHP RCON tool.

Since many people are using this website panel and have no issues , I doubt there is anything wrong with the code as well . The only thing that comes to my mind is my Nginx configuration.

Here is my 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; } } 

Here is my 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; 

And lastly , here is my nginx.conf file :

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; # } #} 

Can anyone please help me get rid of this Nginx error?

1 Answer 1

2

The error message from nginx states that the PHP-FPM socket timed out waiting for a response:

*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" 

That is, the problem occurs at the stage of PHP code execution - it proceed longer than timeouts sets in nginx (60 seconds by default). Most likely, the script is having problems connecting to the game server, or there are other problems. Check the PHP error log.

If you suspect that the code may run for a long time, you can try to increase nginx timeouts by adding in site.conf to location ~ \.php$ the fastcgi_connect_timeout, fastcgi_read_timeout, fastcgi_send_timeout directives with the required number of seconds: https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html

1
  • I asked both data centers to turn off firewall on my IP . The issue was solved so I asked them again to turn on the firewall but whitelist IPs . Thank you for your answer . Commented Dec 28, 2024 at 20:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.