How to Fix 504 Gateway Timeout Error

Samuel Alapakristi
Nov 29 · 2 min read

Many at times as Software developers/engineers we face this kind of error most especially when :

  1. You have an overload or heavy traffic on your server,
  2. You have downtime in your app
  3. Your app is not responding within the server specified response time (usually 30 seconds).

It might be so annoying that lots of hours, even days would have been bygone trying to fixing this kind of error. Rejoice because you will never spend much time trying to fix this error again. Before we dive into the solution, let us understand what the error is all about.

In HTTP request any status code starting with number 5 is server-based. These errors are shown in the image below.

All server error status codes
All server error status codes
Server Errors. (Source

If your app is confirmed running and that there’s no downtime, to solve this error, you simply have to increase your server resources. For PHP-FPM there’s a setting you need to adjust in the file below:


Locate and update then below from its initial default values.
PS If your server has more load and capacity you might want to increase these settings.

pm.max_children = 500
pm.start_servers = 100
pm.min_spare_servers = 50
pm.max_spare_servers = 100
pm.max_requests = 500
request_terminate_timeout = 30s

Once this is done, save the file and restart PHP-FPM.

Thank You for reading and please don’t forget to clap for this post.

Samuel Alapakristi

Written by

Sofware Engineer || Tech Enthusiast || Music Enthusiast || Family Enthusiast

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade