Arama Yap Mesaj Submit
Request a Callback
+90
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro

Contact Us

Location Halkali merkez neighborhood fatih st ozgur apt no 46 , Kucukcekmece , Istanbul , 34303 , TR
NGINX Technical Guide

NGINX 504 Gateway Timeout: A Guide to Proxy and FastCGI Timeouts

504 Gateway Timeout, NGINX’s backend was reached but no response header or data was received within the specified time. This guide explains how to find PHP-FPM, database, external API, import, and application bottlenecks without adjusting timeout settings.

504 Gateway Timeoutupstream timed outproxy_read_timeoutFastCGISlow Query
root@server:~SSH
2026/07/17 03:22:51 [error] 2190#2190: *1147 upstream timed out (110: Connection timed out) while reading response header from upstream
upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock"
Request flowClient, NGINX, and backend connection break point
ConfigurationValidation of active server and location blocks
Live diagnosisLog, socket, port, and service controls
Secure ApplicationTest, controlled reload and result verification
01
Technical description

What NGINX 504 Gateway Timeout shows?

504 indicates that NGINX’s upstream target was reached but no timely available response was received. The root cause could be slow PHP code, a locked database, external API, full worker pool, or internal infinite wait.

The 'while connecting to upstream' phrase in the log indicates a problem with delayed backend responses during connection establishment; 'while reading response header from upstream' indicates a problem with delayed backend responses after connection establishment.

proxy_read_timeout and fastcgi_read_timeout do not limit the total processing time, but rather the waiting time between two consecutive reads. Increasing its value may allow some long-running processes to complete, but it will not eliminate the slow query or blocked worker issue.

If long tasks such as WordPress import, WooCommerce report, large backup, video processing, or external API call are executed within an HTTP request, it is more healthy to move them to a queue, cron, or background worker architecture.

If the 504 only occurs during peak hours, investigate PHP-FPM max_children, application worker count, MySQL slow query, CPU load, and disk delay together.

Measure how long it takes for the same request to be sent directly to the backend before increasing the timeout value; wait time should be optimized, not the duration.

02
Log messages and their meanings

504, upstream timed out and backend wait messages

Search for the phrase you see in the email, browser, or SSH log. Each card includes meaning, probable cause, and safe initial action.

8 registration
01kritik

upstream timed out while reading response header from upstream

Meaning: Backend accepted connection but did not produce initial response header within time.

Possible cause: Slow application, DB lock, full worker or external API.

Call the same endpoint to the backend port directly with curl to measure the duration.
02kritik

upstream timed out while connecting to upstream

Meaning: TCP/socket connection to backend could not be established within the specified time.

Possible cause: Network, backlog, service density, or unreachable target.

Examine port access, SYN states, and proxy_connect_timeout values.
03warning

upstream timed out while reading upstream

Meaning: Response started but exceeded data flow wait time limit.

Possible cause: Slow stream, large output, or backend hang.

Compare response size, buffering, and application log times.
04warning

server reached pm.max_children setting

Meaning: There are no idle workers in the PHP-FPM pool.

Possible cause: Insufficient max_children or long-running PHP requests.

Monitor PHP-FPM slowlog and process times; adjust pool size based on RAM.
05warning

Maximum execution time exceeded

Meaning: PHP has reached its execution time limit.

Possible cause: Slow code, large import, or external service wait.

Optimize the function and query in the fatal line; set the time only when necessary.
06warning

MySQL server has gone away

Meaning: Database connection dropped during long process.

Possible cause: Timeout, packet size, restart, or network issue.

Match MariaDB log and the application query time within the same time frame.
07bilgi

504 Gateway Time-out nginx

Meaning: Browser general timeout page is showing.

Possible cause: Proxy, FastCGI, or upstream response delay.

Find the upstream stage in the NGINX error_log.
08bilgi

client timed out while waiting for request

Meaning: Client request was not completed due to time out.

Possible cause: Slow upload or client connection; upstream 504 should not be confused.

Distinguish between log context and request body process.

No records matching this expression were found.

03
Secure first review

SSH diagnostic commands and what output to look for?

Commands are for root access. Collect only status and logs first; Do not change the permanent setting without seeing the reason.

Origin and backend time measurement
curl -sk -o /dev/null -w 'origin connect=%{time_connect} start=%{time_starttransfer} total=%{time_total}\n' https://example.com/
curl -s -o /dev/null -w 'backend start=%{time_starttransfer} total=%{time_total}\n' http://127.0.0.1:3000/

Shows whether the delay is in front of NGINX or inside the backend.

Timeout logs
grep -R "upstream timed out" /var/log/nginx 2>/dev/null | tail -n 100

It collects which URL and upstream target has a timeout.

Shows active timeout settings.
nginx -T | grep -nE 'proxy_(connect|read|send)_timeout|fastcgi_(connect|read|send)_timeout'

Include files with actual execution times.

System load
uptime
vmstat 1 5
iostat -xz 1 3 2>/dev/null
free -h

Monitors CPU, RAM, run queue, and disk latency.

Database and PHP processes
ps -eo pid,etimes,%cpu,%mem,cmd --sort=-etimes | head -n 30
mysqladmin processlist 2>/dev/null | head -n 50

Displays long-running processes and queries.

Test and reload
nginx -t && systemctl reload nginx
curl -skI --max-time 30 https://example.com/

After changes, secure reload and result test.

04
By hosting environment

Ubuntu/Debian, AlmaLinux/CloudLinux and Plesk controls

Although the root cause of the NGINX error is the same, package paths, service names, security layers and virtual host management vary depending on the Linux distribution or Plesk infrastructure used.

Ubuntu / Debian

NGINX 504 Gateway Timeout for systemd, package path, and journald controls.

  • First, verify the active NGINX configuration and service status.
  • Compare the domain error log with the systemd log in the same time range.
  • Run nginx -t before the change, then perform a graceful reload.
grep -R 'upstream timed out' /var/log/nginx | tail -n 50 systemctl status nginx php8.3-fpm --no-pager journalctl -u php8.3-fpm -n 100 --no-pager

AlmaLinux / CloudLinux

NGINX 504 Gateway Timeout for SELinux, PHP-FPM pool, and RHEL-based service controls.

  • Check the active status of NGINX and related backend services.
  • Review SELinux AVC records and security contexts.
  • Do not restart the service without passing the configuration test.
grep -R 'upstream timed out' /var/log/nginx | tail -n 50 systemctl status nginx php-fpm --no-pager journalctl -u php-fpm -n 100 --no-pager

Plesk Obsidian

NGINX virtual host files generated by Plesk: nginx 504 gateway timeout control.

  • Review the additional directives in the Domains > Apache & nginx Settings section.
  • Separate manually created and Plesk generated files.
  • If necessary, recreate the web configuration for the relevant domain only.
grep -R 'upstream timed out' /var/www/vhosts/system/example.com/logs /var/log/nginx 2>/dev/null | tail -n 50 plesk repair web example.com -n
05
Safe solution order

NGINX 504 Gateway Timeout solution sequence

First, determine whether the delay occurs at the connection, initial response, data transfer, or application-level processing stage.

1

Check the error URL and time.

Log which endpoint is causing the 504, the entire site, or how many seconds it takes for a 504 to occur.

curl -sk -o /dev/null -w '%{http_code} %{time_starttransfer} %{time_total}\n' https://example.com/islem
2

Distinguish the timeout phase in the log.

Classify connecting, reading response header, or reading upstream expressions

grep 'upstream timed out' /var/log/nginx/error.log | tail -n 50
3

Measure the backend without NGINX

Send the same request directly to the application port.

curl -s -o /dev/null -w '%{http_code} %{time_total}\n' http://127.0.0.1:3000/islem
4

Find the application and database bottleneck.

Examine slowlog, long query, API call, and full worker pool.

ps -eo pid,etimes,%cpu,%mem,cmd --sort=-etimes | head -n 30
5

Set a reasonable timeout value only if necessary.

Set the duration according to the expected time of the task in the narrowest location block.

nginx -T | grep -nE 'proxy_read_timeout|fastcgi_read_timeout'
6

Verify under load

Observe worker and time behavior alongside a single request and several concurrent requests.

for i in {1..5}; do curl -sk -o /dev/null -w '%{http_code} %{time_total}\n' https://example.com/islem & done; wait
06
Distinction by symptom

Special scenarios and decision trees

WordPress importunda 504

The import process may be delayed due to PHP time, memory, DB, and external media download.

tail -f wp-content/debug.log /var/log/nginx/error.log
WooCommerce raporunda 504

Large tables and lack of indexes can produce slow queries.

mysqladmin processlist
Timeout during large upload.

Upload timeout and request body limit should be controlled separately.

nginx -T | grep -nE 'client_max_body_size|client_body_timeout'
External API is waiting

The timeout given by the application to the external service can be longer than NGINX.

curl -v --max-time 15 https://api.example.net/health
It only occurs during peak hour.

Examine worker pool, DB connection limit, and CPU saturation.

uptime; free -h; ss -s
Container health is failing

Backend is not responding without restart or readiness might be incorrect.

docker stats --no-stream; docker ps

Absolutely don't

  • Do not set timeout values for each location to unlimited or very high.
  • Do not increase PHP max_execution_time alone without resolving slow queries.
  • Do not restart MySQL unnecessarily during a 504.
  • Do not force long video/import tasks to run within a web request.
  • Do not change the entire server's timeout setting for a single endpoint issue.

Post-solution verification

  • Backend is completing direct request within expected time.
  • NGINX error_log is not generating new upstream timed out records.
  • No max_children warning is found in the PHP-FPM pool.
  • Long/locked queries in the database are under control.
  • Timeout setting is only applied within the necessary server/location scope.
07
Official technical resources

Official documentation of NGINX and related components

08
Internal SEO content set

Related NGINX error solutions

09
Frequently asked questions

NGINX 504 Gateway Timeout Curiosities about

NGINX 504 Gateway Timeout why?

NGINX can reach the backend but fails to respond within the specified time. Slow PHP, database, external API, full worker queue, or network latency are common causes.

Is increasing proxy_read_timeout sufficient?

No. It may help if the process is expected to take a long time; but it can only hide slow query, lock, or crashed worker issues.

What does fastcgi_read_timeout measure?

Measures the waiting time between two consecutive reads from the FastCGI server; does not directly limit the total time of the entire request.

What is the difference between 502 and 504?

502 mostly indicates a failure to connect to the backend or an invalid response; 504 indicates that a connection was established but no response was received in time.

How to diagnose 504 in WordPress?

NGINX error_log, PHP-FPM slowlog, WordPress debug.log and MySQL processlist should be compared within the same time frame.

How to run long import operations?

It should be run independently of HTTP requests if possible, using WP-CLI, cron, queue, or background worker.

What to check if 504 occurs only in heavy traffic?

Examine max_children, application worker count, DB connection limit, CPU load, RAM, and disk latency together.

EKA SOFTWARE AND INFORMATION SYSTEMS

Let's fix the error on your server permanently

By analyzing cPanel, WHM, CloudLinux, LiteSpeed, MariaDB, Exim and security layers together, we fix the root cause of the failure instead of just removing the service.

Get Server Support WhatsApp
Top