How to run Tomcat on port 80

Lokesh Gupta

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 in server.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 !!

Comments

Subscribe
Notify of
guest
4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode