How to make Tomcat work on port 80 instead of 8080?
January 11, 2014 | Posted bySometimes people host applications that are fully Java based and don’t require a Webserver to access their application. However, in such a case, the application has to be accessed with port 8080 i.e. http://domainname:8080 which is not feasible.
There are 2 ways for the Java application to work on port 80, so people don’t have to mention port 8080 in their URL We will take a look at each of the above 2 options below:
1. The easiest way is to change the Tomcat port from port 8080 to 80 in the conf/server.xml file. This file is inside the Tomcat folder.
To locate the file, update the mlocate database first (this command will take sometime to complete):
# updatedb
now, search the server.xml file using the locate command:
# locate server.xml
Open the file in the edit mode
# nano server.xml
and search for the below section
<Connector port="8080" Protocol="HTTP" maxHttpHeaderSize="8192" connectionTimeout="20000" />
Replace port 8080 with 80 and restart the Tomcat service.
2. The second method is to use iptables rules to redirect traffic received on port 80 to port 8080.
To add the iptables redirect rules, SSH to your server as root and execute the below commands:
# iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT # iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT # iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j \ REDIRECT --to-port 8080
To make the rules permanent
# service iptables save
Applying any of the above 2 methods will make the Java application work without the use of port 8080 in the URL.