How to host a java web application live?

When a tomcat 6 is used for a java struts2 web application. How do I access it by using a domain address?
say, when I type, I wanted my application to come up. And I was using an Ubuntu server 12.04 LTS I think.

I am not really sure about what should be the right way to do it. However I have managed to get this done.

Before explaining that, I think below is one of the right method to implement.

The above site explanation was little tough for me to understand. So I tried other ways.

1. Inside tomcat webapps, there is a ROOT Folder with index.jsp file in it. I renamed the root folder to ROOTBKUP.


2. Then renamed my application's folder name inside webapps to ROOT folder.

sudo mv xyz ROOT

3. Now if you already set up your firewall, then you will need to allow incoming connections from 80, 8080, 443, 8443

iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT

iptables -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 8443 -j ACCEPT

4. After allowing incoming connections thru above ports, then you need to redirect the connections coming to 80 to 8080 and
similarly 443 to 8443

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

5. You may restart the tomcat server now.

This would work only if you are planning for hosting only one application in a server according to me. People
with more expertize in this area should be able to guide you guys for multiple hosting.

Good luck! :)

1 comment:

  1. This blog is nice and very informative. I like this blog.
    blog Please keep it up.