Why does Tomcat work with port 8080 but not 80?
42,350
Solution 1
go to /etc/default/tomcat6 and change #AUTHBIND=no
to AUTHBIND=yes
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind. It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4. Do not enable it when using IPv6.
# (yes/no, default: no)
#AUTHBIND=no
Solution 2
Two typical reasons:
- You quite possibly don't have permission to listen to a port lower than 1024 (usually requires administrative privileges, e.g. being
root
) - Something else may already be listening on port 80 (e.g. apache)
Solution 3
If nothing of the commented before works (like it happened to me), you can direct the traffic from the port 80
to the 8080
.
To do it:
http://forum.slicehost.com/index.php?p=/discussion/2497/iptables-redirect-port-80-to-port-8080/p1
In a nutshell, type this three commands in a terminal:
$ sudo iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
$ sudo iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
$ sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
Solution 4
Did you start Tomcat on port 80 as root? You have to be root to bind to ports <= 1024 in Linux.
Solution 5
Run your startup script as root after changing the binding.
sudo ./<path to tomcat bin director>/startup.sh
Author by
Dominik
Updated on January 19, 2021Comments
-
Dominik over 3 years
I have started and tested Tomcat under Port 8080 (default). Now I altered the connector port to 80 and restarted Tomcat, nothing will show on my minimal Debian 6.0 installation. Now where is the trick here?
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" URIEncoding="UTF-8" redirectPort="8443" />
-
Romain about 12 yearsWorth noting: starting Tomcat as
root
is generally a bad idea, security-wise, unless it is able (and configured) to switch its user to a non-privileged user after binding (which wasn't possible last time I checked). -
Romain about 12 yearsWhat about the fact ports <= 1024 are privileged?
-
Romain about 12 yearsNothing in the OP mentions that. You shouldn't assume.
-
Dominik about 12 yearsI am pretty sure there is nothing running on 80 since its a basic debian with only SSH installed, I added java and tomcat with apt-get.
-
Jon Skeet about 12 years@Romain: Well, root or a similarly privileged account. Have edited to clarify. I believe 1024 would be okay (i.e. it's only 0-1023 which require privilege, but I could be wrong)
-
Dominik about 12 yearsThere is no Apache running nor anything else at port 80
-
Dominik about 12 yearsI started Tomcat using /etc/init.d/tomcat6 start logged in with the root account. Can I modify it so I can start it under port 80?
-
Dominik about 12 yearsNothing else is listening on port 80. I am root but I am executing it with /etc/init.d/tomcat6 start
-
rooftop about 12 yearsThe tomcat configuration files are what determine which port to use, how you start the process doesn't really matter. Chances are you either have something else listening on port 80. Try running: netstat -an | grep 80 That will let you know if something is already listening on port 80.
-
Dominik about 12 years
-
emecas about 11 yearsit will be just an extreme case, as you have mentioned "If nothing of the commented before have worked".
-
rich p over 9 yearsOther readers are seeing something that I'm missing: * This is simple and accomplishes the goal without having to install & administer
authbind
. * Tomcat listens on the low-number ports. * Tomcat runs as a non-privileged user. Why is this an extreme case solution? -
alexk about 8 yearsThis solution isn't great because the end user will see the port number in their URL and see a URL change.
-
Mohan Seth almost 8 yearsPerfect solution, saved my day
-
Koray Tugay over 7 yearsCorrect answer for *nix but what about Windows?
-
Arya over 6 years@Romain what would you say is the best way to make Tomcat accessible on port 80? Install both Apache httpd server and Tomcat and then use Apache httpd server to proxy to Tomcat using mod_proxy?
-
Romain about 6 years@arya I pues so - Tomcat + some reverse proxy (Apache, Nginx, whatever suits your use-case best)
-
Gonza over 4 years@alexk I'm not having the URL change issue with this solution -I know this is a really old thread.