A 504 error is usually displayed when the connection between your browser and the web server is held open for more than 180 seconds, causing an HTTP timeout to occur.

When multiple requests come in at or near the same time, some requests may need to wait in line to be handled. So, even though the server may be processing requests, if each one is taking a long time to be processed, a large number of requests can stack up. When the queue gets too big, and processes wait too long, the older requests are disregarded by the server, causing a 504 gateway error to be returned.

Like most error troubleshooting, the first step is to figure out the root cause of the error.

Finding and Resolving a 504 Gateway Timeout Error

Errors During Import

If the error is occurring during an import, try running the import directly on the server using WP-CLI or a local PHP or Bash script. This will bypass the HTTP connection entirely, allowing you to complete the import without a 504 error.

Third-Party CDN

If your site uses a third-party CDN in addition to Kinsta’s Cloudflare integration, temporarily disable or bypass that CDN.

Check Upload Path

If you’re seeing an error related to the file path when trying to upload a file (e.g. adding and uploading an image to content), the upload path may be incorrect. This is most common right after migrating a site. Depending on the configuration at your previous host, the upload path may have been customized. This can be seen in either the wp_options table or in the WordPress dashboard (Settings > Media > Uploading Files).

In the WordPress dashboard, if you see options labeled Store uploads in this folder and Full URL path to files, they have been customized. The corresponding data in the database can be found in the wp_options table in the upload_path and upload_url_path options.

You can delete anything in those fields (either in the WordPress dashboard or the database) to set them back to their defaults.

File Size of Uploads

If you’re seeing an error related to file size when trying to upload a file, check the size of the file(s) you’re trying to upload. Some CDNs limit the size of files you can upload. If you’re using a third-party CDN, check the maximum upload size in your CDN settings and make sure your uploads are less than the maximum. Or, if your site requires the file size to be that large, adjust the maximum upload size at your CDN (if possible).

Corrupted Database

Occasionally, a corrupted database can be the source of 504 errors. If you see errors that indicate a corrupted database (e.g. “One or more database tables are unavailable. The database may need to be repaired.” when logging into the WordPress dashboard) see our guide on repairing a corrupt database.

Plugins and Themes

While it isn’t as common, sometimes a plugin or theme can be the source of a 504 error. The best way to test for this is to deactivate all plugins and switch to a default theme. If the issue is resolved, reactivate plugins one by one and reactivate your theme until the issue reoccurs. Once you’ve determined which plugin or theme is the source, send a copy of the error to the plugin or theme developer so they can help you resolve the issue.

Error Log

Check the error.log for your site in MyKinsta (or download via SFTP) to narrow down the source of the error. If nothing obvious stands out, it may be helpful to enable WP-DEBUG.

Traffic and Caching

Check the Visitors report in MyKinsta analytics to see if your site is experiencing a traffic spike and/or a large number of un-cached requests. Opening a chat with our Support team can be helpful in this case, so we can help you determine if the requests are legitimate and if more resources (like PHP workers) may be needed.

Increase Number of PHP Workers

In some cases, more PHP workers may be needed. If you’re not sure, our Support team can help you determine if adding more PHP workers is needed for your site.

Throttling Traffic

If your site is experiencing a traffic spike or just more traffic in general, and increasing resources isn’t an option, an alternative to keep too many requests from coming in all at once to the server is to implement a queuing system like Queue-it, Queue-Fair, or Crowdhandler.