By default, Tomcat is configured to run on port 8080
. That’s why all the deployed web applications are accessible though URLs like http://localhost:8080/yourapp
.
If you want to run an application on URL like http://localhost/yourapp
, then you will need to change the default port 8080 to 80, which is default port for HTTP connectors.
1. Change port to 80 in tomcat’s server.xml
To make this port change, open server.xml
and find below entry :
<Connector port="8080" //Change this protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
and change it to below entry:
<Connector port="80" //Changed !! protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
You are all set to access your applications using root path “http://localhost/
“.
2. Changing port in Linux
In linux, port upto 1024 are reserved ports. So, to use any port below this (e.g. port 80 in our case), we must make additional configuration changes.
2.1. With root access
This one is easy. Simply start the Tomcat process as root.
sudo startup.sh
2.2. Without root access
If we do not have root access, we must install and configure authbind package. It helps in binding sockets to privileged ports without root.
- Install
authbind
.sudo apt-get install authbind
- Enable
authbind
inserver.xml
.AUTHBIND=yes
- Configure tomcat in authbind if permission denied error comes (EPERM – Operation not permitted, or Not owner), use these command to enable access.
sudo touch /etc/authbind/byport/80 sudo chmod 500 /etc/authbind/byport/80 sudo chown tomcat8 /etc/authbind/byport/80
- At last, restart the tomcat server if it is running already.
Happy Learning !!
shubham
any other option without change in server.xml.I dont want my port will show in url .Mail me as soon as possible.
Jpp67
Yes, this will probably not be very useful, too basic. Why not to change the redirect port by the time ?
The real point about this topic is how to manage this under Linux/UNIX as the 1024 first ports require special privileges. Regards
mauro
HI .i have read your article for run tomcat on port 80.
But i have read from many web sites that the first 1024 port are reserved and not usable .
Is only for linux ?
I know that so i not have to put a apache like front end for redirect at port 8080 .
Let me know please .
Tank you for all your beatiful articles.
Mauro
Lokesh Gupta
Yes, restriction is linux specific. Regarding port 80, it’s default for HTTP so you should be able to use it without any issue irrespective of underlying OS.