Tag: Tomcat

How to deploy an app to remote Tomcat using port 80 on Amazon EC2

How to deploy an app to remote Tomcat using port 80 on Amazon EC2

Let’s suppose you already have a .war file of your application and Ubuntu Ec2 instance configured out with java and tomcat.

1. First of all (and optional): Get a free domain on dot.tk and made a redirect throught the dns manager to ip given by amazon elastic ip.  You can also use a 3rd part dns manager, like ZoneEdit.

2. After that, do a modification in conf/server.xml file of tomcat instalation, to add the application to context path “/” or ROOT. Run sudo nano server.xml and type inside the tag “<Host>”:

<Context path=“/” docBase=”theprojectname”> </Context>

3. For security reasons, Ubuntu has disabled tcp requests with low ports, but as we want our application responding at :80, let’s make a firewall rule to redirect calls from port :80 to port :8080 of tomcat.  type:

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 80 -j REDIRECT –to-port 8080

There are many others options to do that, like using ngnix, an Apache Virtual Host or even authbinding the use of :80. As soon as we want to keep it simple, the rule above works like a charm.

4. (important) Amazon’s Instances have its own firewall rule as well. The default mode keeps only port 22 (ssh) opened. So alter amazon ec2 security group adding new rule that allows http port 80.

5. (extra) As the amazon free instance (micro) has only 1gb of memory, you might need some more space to allocate apps. I did this with a swapfile, following this wonderful tutorial from digitalocean:

https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04