How to change tomcat 8 port
I am trying to change the Tomcat's port to 80 in Ubuntu 14.04 through this configuration [conf/server.xml]:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
to:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
And I am receiving this error:
13-Oct-2015 18:09:10.626 SEVERE [main] org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["http-nio-80"]
java.net.SocketException: Permission denied
What I am doing wrong? Or what is missing?
Thanks...
To run Tomcat on a port below 1024 in Ubuntu/Unix, the service needs root privileges. And that you do not want.
Use a port redirection via iptables
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
Start tomcat services using authbind this will allow user to start ports less than 1024 we do not need to redirect or iptables.
sudo apt-get install authbind -y
To install Authbind software
sudo chmod -R 755 /etc/authbind
group should be user group.
sudo chown -Rh root:group /etc/authbind
After that run the below commands
cd /etc/authbind/byuid
As an example lets imagne user id is 2000 you can use your user id number
sudo echo '0.0.0.0/0:1,1023' > 2000
That file should be own by user and group.
sudo chown : 2000
sudo chmod 700 2000
Add the below line in tomcat startup file $CATALINA_BASE/startup.sh
export JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
For Starting tomcat using Authbind service startup.sh
Comment the below line
#$CATALINA_HOME/bin/startup.sh
Add This End as the end of the file
AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c "
$AUTHBIND_COMMAND $CATALINA_HOME/bin/startup.sh
now you should be able to start tomcat services as user with less that 1024 ports.