Running tomcat port 80

Standard

The Hypertext Transfer Protocol (HTTP) is the foundation of data communication for the web. By default Tomcat does not use port 80 for communication. Tomcat runs on port 8080 instead. UsingĀ iptables all traffic can be pre-routed from port 80 to port 8080, or all traffic from port 443 (SSL) to port 8443 (tomcat SSL port). This walkthrough shows how to setup port 80 forwarding in Centos 6.x.

To do this modify your iptables file and replace the contents with the following.

vi /etc/sysconfig/iptables

Past in the following:

# Generated by iptables-save v1.4.18 on Mon Aug 19 16:38:51 2013
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [8:1088]
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 8000 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 21100:21299 -j ACCEPT
COMMIT
# Completed on Mon Aug 19 16:38:51 2013
# Generated by iptables-save v1.4.18 on Mon Aug 19 16:38:51 2013
*nat
:PREROUTING ACCEPT [2:104]
:OUTPUT ACCEPT [7:558]
:POSTROUTING ACCEPT [7:558]
# These lines direct all traffic to tomcat
-A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
-A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8443
COMMIT

Finally, restart iptables to apply the changes:

service iptables restart