Uncomplicated Firewall eases configuration of firewall in ubuntu and eases iptable configuration.

While configuring webserver in EC2 you might find that you have done everything right with your webserver, DNS zone file and Security Groups of EC2 instance, but still the website is not loading.

The most probable reason might be mal-configured firewall of ubuntu. It is best to configure it from scratch, allowing only the required ports.

If ufw is not installed run the following command

sudo apt-get update
sudo apt-get install ufw

Step to enable ufw

By default ufw is not enabled


sudo ufw enable

Check the status of firewall

sudo ufw status 

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere
80                         ALLOW       Anywhere
22 (v6)                    ALLOW       Anywhere (v6)
80 (v6)                    ALLOW       Anywhere (v6)

Steps to allow ports

sudo ufw allow http

or

sudo ufw allow 80

for custom port number

sudo ufw allow 8080/tcp
sudo ufw allow 8080/udp

General syntax for allow:

sudo ufw allow PORT/PROTOCOL

Step to disallow and delete

sudo ufw deny 8080

General syntax for disallow:

sudo ufw deny /

To delete a rule already exist append 'delete' before the rule

sudo delete deny 8080/tcp 

To allow access from a set of IPs

sudo ufw allow from 192.168.1.0/24

or only one IP

sudo ufw allow from 54.87.215.87 

To disable ufw

sudo ufw disable 

Hope this helps you in configuring your ubuntu box.
Refer here for more details.