How to run tomcat 8.5 on port 80 / remove 8080. tomcat 8.5.16, centos 7minimal install, hosting 24

danbdex picture danbdex · Aug 5, 2017 · Viewed 8.9k times · Source

This question is unique to Tomcat 8.5 other answers are for 7 and do not work as described

Firstly I've been studying tomcat docs, and online questions for 20 hours now. I've built my server from scratch about ten times to learn the process and try and get a clear guide written to get a server up and running for running multiple spring boot web apps.

I cannot at the moment get tomcat to run on port 80 so no "8080" at the end of the domain name. It Runs on port 8080 fine.

"netstat -lnp grep 80" shows me this:

enterProto Recv-Q Send-Q Local Address           Foreign Address         
State       PID/Program name
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               
LISTEN      449/mysqld
tcp        0      0 0.0.0.0:111             0.0.0.0:*               
LISTEN      1/init
tcp        0      0 0.0.0.0:22              0.0.0.0:*               
LISTEN      143/sshd
tcp6       0      0 :::8001                 :::*                    
LISTEN      139/httpd
tcp6       0      0 127.0.0.1:8005          :::*                    
LISTEN      281/java
tcp6       0      0 :::8009                 :::*                    
LISTEN      281/java
tcp6       0      0 :::21                   :::*                    
LISTEN      147/vsftpd
tcp6       0      0 :::22                   :::*                    
LISTEN 

So nothing using port 80. systemctl status tomcat.service = running

firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: venet0 sources: services: dhcpv6-client ssh ports: 8001/tcp 80/tcp 20/tcp protocols: masquerade: no forward-ports: sourceports: icmp-blocks: rich rules:

port open on public zone.

The method I'm trying at the moment is to change the port in the tomcat/conf/server.xml

here is where I've changed it:

{<Connector port="80" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
}

nmap and online tools say port is closed but I beleive that is because there is nothing using the port. Just what I've read so don't know for sure.

Also no rules in iptables so no other port blocks in place.

The web page displayed shows "This site can’t be reached"

Any help would be greatly appreciated as I've spend 20 solid hours studying server setups and am still baffled as to how to really check why this doesn't work but why it works on port 8080.

I'm trying to run multiple webapps through tomcat. I'm planning on adding the host details to the bottom of the server.xml which I have done succesfully on port 8080 but not on port 80 same result as above.

This is a similar question to previous ones but the answers do not work I have tried them all.

Answer

aleroot picture aleroot · Aug 5, 2017

You have to enable AUTHBIND on Linux to let tomcat use a privileged port like the 80, so set AUTHBIND=yes in /etc/default/tomcat8 file .

Another solution could be, using the default port(80) and redirecting all the requests from port 80 to port 8080 with iptables in this way :

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