Question

How to enable port 80 on Apache tomcat?

I have installed Apache tomcat on my Droplet and deployed my application. It is available on port 8080. How can I make it available on port 80? Thank you!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
October 4, 2023

Heya,

To make your Tomcat application available on port 80, you have several options:

  1. Reconfigure Tomcat to Listen on Port 80 Directly:
  • Open the server.xml file which is located in the conf directory of your Tomcat installation:
sudo nano /path/to/tomcat/conf/server.xml
  • Find the line that starts with <Connector and has port="8080". Change 8080 to 80:
<Connector port="80" protocol="HTTP/1.1" ... />
  • Save and close the file.
  • Restart Tomcat.
  • Note: Running Tomcat on ports below 1024 requires root privileges. Running Tomcat as root is not recommended due to potential security risks. Hence, the below methods might be more suitable for most use cases.
  1. Use a Reverse Proxy (e.g., Apache or Nginx):

This method involves setting up another web server in front of Tomcat to handle incoming requests on port 80 and then forward them to Tomcat on port 8080.

  • For example, with Nginx, you would install Nginx and then set up a configuration like:
server {
    listen 80;
    
    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
  • Reload or restart Nginx after modifying the configuration.

This approach has the added benefit of allowing you to easily set up SSL/TLS encryption, load balance between multiple Tomcat instances, or serve static assets directly from the reverse proxy for better performance.

Bobby Iliev
Site Moderator
Site Moderator badge
March 15, 2023

Hi there,

You should be able to do that by following these steps

  • Edit the Tomcat server.xml configuration file, the locaiton of the file might depend on the way that you’ve installed Tomcat, but popular locations are at /opt/tomcat/conf/ or /etc/tomcatVERSION
  • After that find the <Connector port="8080" protocol="HTTP/1.1" line, and change the port from 8080 to 80
  • Finally restart Tomcat

Let me know how it goes!

Best,

Bobby

Hello @sergeigerman,

To change default port number, edit the main Connector element in the server.xml file. Find XML tag that looks something like this:

<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

Just change the port attribute from 8080 to 80, and restart Tomcat. Unless that port number is already in use or you lack administrative permission to start a server on port 80, Tomcat should now be operational on port 80.

Let me know how it goes,

Sergio Turpín

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel