Web Development

How to Fix Timeout When Trying to Connect to AWS EC2 Web Server

May 13, 2019

When trying to connect to a new web server hosted on AWS EC2, your browser may try to load the page for a long time and then subsequently return a timeout error. This can be quite annoying, especially after spending a lot of time configuring your server. There is good news though — the solution is often very simple. Here are a few ways you can stop this issue from happening.

Make sure your security group is configured correctly

The the most common and easy to miss reason is a incorrectly configured security group. A security group, in part, defines what ports are open to the internet. If ports such as 80 for HTTP traffic, and 443 for HTTPS traffic are not enabled as a rule, AWS will block traffic on those ports.

You can fix this issue by going to the Instances page on AWS, and then clicking on your instance. Then on the bottom panel, look for Security Groups. Then click on the name of the security group. This will take you to the security group page. On this page, select the Inbound tab on the bottom panel. Add a group for HTTP traffic, and HTTPS traffic if you have set it up.

Make sure your instance is actually running

This may seem like a no-brainer, but it can still be overlooked. Make sure that the status of your instance is “running”.

Check for processes using 100% cpu

Sometimes a process that is taking a large amount of resources can prevent apache or nginx from returning a resource before timing out.

You can use the top command to check for processes that have high cpu utilization and then terminate then using sudo kill [pid] substuting the id of the process in question.

There were the most common reasons you may encounter a timeout error when trying to connect to your EC2 based web server. Happy AWSing!