How to Make Tomcat Respond to Port 80

  • by
Tomcat uses port 8080 to service public users, but most users won't append :8080 to your URLs to get the content, which will result no content returned on clients. Therefore, you need to make Tomcat respond to port 80 by yourself. In this post, I introduce 2 ways to achieve this goal, assuming that you have opened port 80 on the firewall.
  1. Make Tomcat listen to port 80.
  2. Forward the traffic of port 80 to port 8080.

A. Make Tomcat listen to port 80.

  1. Change listening port from 8080 to 80.
[root@test ~]# vi $CATALINA_HOME/conf/server.xml
...
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

...

  2. Restart Tomcat to listen port 80.
[root@test ~]# $CATALINA_HOME/bin/shutdown.sh
...
[root@test ~]# $CATALINA_HOME/bin/startup.sh
...
Tomcat started.


B. Forward traffic of port 80 to port 8080.

 Create a forward rule for both runtime and permanent on Enterprise Linux 7.
[root@test ~]# firewall-cmd --zone=public --add-forward-port=port=80:proto=tcp:toport=8080
success
[root@test ~]# firewall-cmd --zone=public --add-forward-port=port=80:proto=tcp:toport=8080 --permanent
success

The above commands create a rule on firewall to forward all incoming packets of port 80 to port 8080 by firewall-cmd, which also means that making 80 an alias port of 8080.

The forward or alias technique could make the web server more flexible if there's a chance to build a true http service on port 80 underlyingly in the future.

For more firewall distinctions, you may refer to this post:
How to Open Ports on IPTABLES and Survive across Reboots on Enterprise Linux 6 and 7

Leave a Reply

Your email address will not be published. Required fields are marked *