Can not access EC2 server via IP address

I am having this problem accessing my elastic public IP for my EC2 instance in the web browser. Installed REDHAT 6.3 and installed nginx web server(up and running) and also made sure i enabled port 80 and everything needed was setup.

Now time to enter the public IP to view the default nginx web page and nothing happens. I couldn't access the IP address.

Now i could ping other websites but couldn't ping my IP address.

Now after several hours of trying and trying to figure out what was going on...i figured i should check the networking on the REDHAT OS and whenever i try to edit anything network related..that is it i lost connection to the server and cannot restart the network.

What am i getting wrong here? Why is just accessing my server through IP such a difficult thing? What do i need to do now?

Thanks.

EDIT. here is the security group associated with the EC2 instance

Ports   Protocol    Source
20-21   tcp 0.0.0.0/0   
22  tcp 0.0.0.0/0   
80  tcp 0.0.0.0/0   
14000-14050 tcp 0.0.0.0/0

Solution 1:

So, There are be few things which might be wrong here. You can test them one by one and zero down to the issue.

  1. First check whether you are able to connect to the port from outside. To do that, use this command

    # telnet IP 80
    

    If you are able to connect through this, then it means there is something surely wrong with your WebServer settings and you shouldn't be looking at the next rules.

  2. If first one doesn't work, the second thing to check is your iptables in your machine, not just the AWS security group. To do the same, check the output of this command.

    # iptables -L -n
    

    The default policies should always be ACCEPT, if you are not specifically putting then to DROP or REJECT. To test whether iptables is the issue or not, you can try disabling iptables by flushing the rules or stopping your iptables service.

    To flush the rules, use this command:

    # iptables -F
    

    To stop the iptables service:

    # service iptables stop
    

    Now try to access your site.

  3. The third option is to check the Selinux on your machine. On redhat machine, SElinux is by default enabled. To check the same, use this command and check for the status:

    # getsebool
    

    It should say something like this:

    getsebool:  SELinux is disabled
    

    If it's enabled, then it could be the cause. Just try disabling it temporarily with this command:

    # setenforce 0
    

    This will disable the SElinux on your machine on temporarily basis. If this fixes your issue, just update the state from Enforcing to disabled in /etc/sysconfig/selinux and it will disable SElinux at your machine permanently.

Hope this helped.

Solution 2:

If it's just web traffic and you can still ssh to your instance, then it's almost certainly something to do with your configuration of nginx.

Solution 3:

GeekRide did a great job of highlighting different troubleshooting steps. The answer for my deployment was related to the iptables. Stopping the service is a great tip to quickly identify the issue.

To solve the issue, be sure to "insert" your port into the table. Do not append, as you will most likely be appending after a "reject all" entry that is at the end of the list. This example uses 5 to be placed after the port 22 rule. In aws since you connect as ec2-user, add the sudo command.

# sudu su
# iptables -L -n
# iptables -I INPUT 5 -p tcp --dport XXXXX -j ACCEPT

If that works, be sure to save in case the iptables service is restarted

# iptables-save