Skip to content

How do I troubleshoot an HTTP 504 "Gateway Timeout" error message in Lightsail?

3 minute read
0

I want to troubleshoot an HTTP 504 "Gateway Timeout" error message that I receive on my website hosted on Amazon Lightsail.

Short description

If Lightsail experiences connectivity issues between the proxy and the web server, then you receive the HTTP 504 "Gateway Timeout" error message. You also receive an HTTP 504 if Lightsail doesn't have enough available memory and disk space or if the gateway or proxy server's timeout duration is too short.

To resolve, check that Lightsail the network connectivity establishes. Then, check that Lightsail has enough available resources. To resolve, you can also increase the gateway or proxy server's timeout duration.

Resolution

Note: It's a best practice to create a snapshot of your Lightsail instance as a backup before you make any changes.

Check the network connectivity

To check for network connectivity issues between the proxy and backend server, complete the following steps:

  1. Open the Lightsail console.
  2. Navigate to the proxy server instance where the error occurs.
  3. Choose the Networking tab.
  4. Check that your firewall rules allow inbound traffic from the proxy and backend server on the required ports.
  5. If the rules allow inbound and outbound traffic, then run the following telnet command from the proxy server to test your connectivity:
    telnet example-backend-server-ip example-backend-server-port
    Note: Replace example-backend-server-ip with the backend server's IP address. Replace example-backend-server-port with the port that the proxy server uses to connect to the backend server.

Check that Lightsail has sufficient memory and disk space

Check that Lightsail has enough memory and disk space. If your Lightsail instance consistently uses too much memory, then optimize your application to reduce memory usage. If your instance still uses a large amount of memory, then scale up your instance to a larger plan.

If the disk space of your instance is full or nearly full, then remove unnecessary files and clear your caches. If the disk space of your instance is still full, then increase the disk size of your instance.

Increase the gateway or proxy server's timeout duration

If you use a web-server proxy and applications time out, then use SSH to connect to Lightsail. Then, increase the timeout value for your web-server, your proxy server, and the PHP application.

Take the following actions based on your server.

For Apache, see Apache Proxy Timeout with PHP-FPM on the Control Web Panel website and Workers on the Apache website.

For Nginx Proxy, see How To Fix 504 Gateway Timeout Errors In NGINX on the Netdata website. Also, see An operation or a script that takes more than 60 seconds to complete fails on a website hosted in Plesk: nginx 504 Gateway Time-out on the Plesk website.

Related information

HTTP 504 status code (Gateway Timeout)

How do I troubleshoot 504 errors that I receive when I use an Application Load Balancer?

How do I troubleshoot 504 errors in CloudFront?

AWS OFFICIALUpdated a month ago