Skip to main content

TOMCAT8 - CHANGING DEFAULT PORT(8080) TO 80 (PRIVILEGED PORT)

First install tomcat 8 from source (Assumed to be installed in /opt/tomcat)
http://www.goserverspace.blogspot.com/2017/10/installing-tomcat-8-in-centos-7.html

Edit server.xml file
#vi  TOMCAT HOME/conf/server.xml
Search "Connector port"
Replace "8080" by your port number
But for portnumber less than 1024(privilaged ports) we can't do this. For that inaddition to these we have to make following changes.

CENTOS:
Install authbind
#wget https://s3.amazonaws.com/aaronsilber/public/authbind-2.1.1-0.1.x86_64.rpm
#yum install authbind-*

Make port 80 available to authbind (you need to be root):
touch /etc/authbind/byport/80
chmod 500 /etc/authbind/byport/80
chown tomcat7 /etc/authbind/byport/80

Make IPv4 the default (authbind does not currently support IPv6).
To do so, create the file TOMCAT/bin/setenv.sh with the following content: (here in /opt/tomcat/bin/setenv.sh)
CATALINA_OPTS="-Djava.net.preferIPv4Stack=true"

Change /usr/share/tomcat7/bin/startup.sh
exec authbind --deep "$PRGDIR"/"$EXECUTABLE" start "$@"
# OLD: exec "$PRGDIR"/"$EXECUTABLE" start "$@

[[If you already got a setenv.sh file in /usr/share/tomcat7/bin with CATALINA_OPTS, you have to use :
export CATALINA_OPTS="$CATALINA_OPTS -Djava.net.preferIPv4Stack=true"]]

Now make changes in /opt/tomcat/conf/server.xml file to change port(for 443 we have to crete keystroke file.follow the document for it)

Now restart service
#service tomcat restart

UBUNTU:
Install authbind package
#apt-get install authbind

Make port 80 available to authbind (you need to be root):
#touch /etc/authbind/byport/80
#chmod 500 /etc/authbind/byport/80
#chown tomcat7 /etc/authbind/byport/80

#vi /etc/default/tomcat7
Make the AUTHBIND=no to AUTHBIND=yes
AUTHBIND=YES

Now restart service
#service tomcat restart