Install and configure Apache Tomcat with a reverse proxy for beginners

Beginner 35 min Nov 27, 2026
Ubuntu 24.04 Ubuntu 22.04 Debian 12 Debian 11 AlmaLinux 9 Rocky Linux 9 Fedora 41

Learn how to install Java and Apache Tomcat, understand its directory structure, deploy a basic web application, and put Nginx in front of it as a reverse proxy with proper firewall rules.

Prerequisites

  • A server running Ubuntu, Debian, AlmaLinux, Rocky Linux or Fedora with root or sudo access
  • At least 1GB RAM and 10GB free disk space
  • A domain name pointed at your server's IP address (optional but recommended)
  • Basic familiarity with the Linux command line

What this solves

Apache Tomcat is the standard way to run Java web applications on Linux. This tutorial walks you through installing Java and Tomcat, understanding its default layout and ports, deploying a sample application, and placing Nginx in front of it as a reverse proxy so you can serve Tomcat on standard HTTP ports with a proper domain.

By the end you will have Tomcat running as a systemd service, Nginx forwarding traffic to it, and a firewall configured to only expose the ports you actually need.

Step-by-step installation

Install Java

Tomcat runs on the Java Virtual Machine, so you need a JDK installed first. OpenJDK 17 is a solid, widely supported choice for Tomcat 10 and 11.

sudo apt update
sudo apt install -y openjdk-17-jdk
sudo dnf install -y java-17-openjdk java-17-openjdk-devel

Verify the Java installation

Confirm the JDK is installed and check the version before moving on.

java -version

Create a dedicated Tomcat user

Tomcat should never run as root. Create a system account with no login shell to own the Tomcat files and process.

sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat

Download and extract Tomcat

Download the latest Tomcat 10 release directly from the Apache archive and extract it into /opt/tomcat.

cd /tmp
curl -O https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.33/bin/apache-tomcat-10.1.33.tar.gz
sudo tar xzf apache-tomcat-10.1.33.tar.gz -C /opt/tomcat --strip-components=1
Note: Check the official Tomcat downloads page for the current release number before running this command, since version numbers change over time.

Set correct ownership and permissions

Tomcat needs its scripts to be executable by the tomcat user, and its config files should not be world writable. Never use chmod 777 to work around permission errors, it gives every user on the system full read, write and execute access to your application files.

sudo chown -R tomcat:tomcat /opt/tomcat
sudo chmod -R 750 /opt/tomcat
sudo chmod -R +x /opt/tomcat/bin
Never use chmod 777. It gives every user on the system full access to your files. Instead, fix ownership with chown and use minimal permissions like 750 for directories and 640 for config files owned by the tomcat user.

Create a systemd service

Running Tomcat under systemd gives you automatic restarts, boot-time startup, and standard log handling through journald.

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking
User=tomcat
Group=tomcat
Environment=JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target
Note: On AlmaLinux, Rocky Linux and Fedora the JAVA_HOME path is usually /usr/lib/jvm/java-17-openjdk without an architecture suffix. Run sudo alternatives --config java to confirm the exact path on your system.

Enable and start the Tomcat service

Reload systemd so it picks up the new unit file, then enable and start Tomcat.

sudo systemctl daemon-reload
sudo systemctl enable --now tomcat
sudo systemctl status tomcat

If the service fails to start, check the exit code and logs before troubleshooting further. The systemd 203/EXEC guide covers a common cause of startup failures related to incorrect paths or permissions.

Understanding the Tomcat directory structure and default ports

Everything Tomcat needs lives under CATALINA_HOME, which in this setup is /opt/tomcat. Knowing what each directory does makes troubleshooting much faster.

DirectoryPurpose
binStartup and shutdown scripts
confConfiguration files including server.xml and web.xml
webappsDeployed web applications, one folder or WAR file per app
logsCatalina and access logs
tempTemporary files used at runtime
workCompiled JSP output and session data

By default, Tomcat listens on port 8080 for HTTP and port 8005 for the shutdown command. Port 8080 is not meant to be exposed directly to the internet in production, which is exactly why you put Nginx in front of it.

Configuring a basic web application deployment

Deploy a sample application

Tomcat auto-deploys anything dropped into webapps. Create a minimal JSP page to confirm deployments work end to end.

sudo mkdir -p /opt/tomcat/webapps/demo
echo '<html><body><h1>Tomcat demo app is running</h1></body></html>' | sudo tee /opt/tomcat/webapps/demo/index.jsp
sudo chown -R tomcat:tomcat /opt/tomcat/webapps/demo

Secure the manager and host-manager apps

The manager interface lets you deploy and undeploy applications through a browser. Restrict it to roles with real credentials instead of leaving it open.

<tomcat-users>
  <role rolename="manager-gui"/>
  <user username="tomcatadmin" password="Ch4ng3-This-Str0ng-Pass" roles="manager-gui"/>
</tomcat-users>

Restart Tomcat after editing this file so the new credentials take effect.

sudo systemctl restart tomcat

Setting up Nginx as a reverse proxy for Tomcat

Install Nginx

Nginx will sit in front of Tomcat, handling port 80 and 443 while forwarding requests internally to port 8080.

sudo apt install -y nginx
sudo dnf install -y nginx

Create a reverse proxy server block

This configuration forwards all traffic for example.com to Tomcat on localhost port 8080, while preserving the original client IP and host headers.

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1: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;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
Note: If you are new to Nginx server blocks and virtual hosts, the Nginx virtual hosts tutorial covers the basics in more depth.

Enable the site and test the configuration

On Debian and Ubuntu, symlink the config into sites-enabled. On RHEL-based distros, Nginx reads directly from conf.d.

sudo ln -s /etc/nginx/sites-available/tomcat.conf /etc/nginx/sites-enabled/tomcat.conf
sudo nginx -t
sudo systemctl reload nginx
sudo cp /etc/nginx/sites-available/tomcat.conf /etc/nginx/conf.d/tomcat.conf
sudo nginx -t
sudo systemctl reload nginx

For production deployments you should terminate TLS at Nginx rather than serving plain HTTP. See the Tomcat SSL with Let's Encrypt tutorial once this basic setup is working, or the general Nginx SSL termination with Certbot guide for the Nginx side.

Basic firewall rules for web traffic

Allow only HTTP, HTTPS and SSH

Tomcat's port 8080 should never be reachable from outside the server once Nginx is in front of it. Only open the ports clients actually need.

sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
Note: Since Nginx proxies requests internally over localhost, port 8080 does not need to be opened in the firewall at all. Leaving it closed is the correct default.

Verify your setup

Check that Tomcat is running and listening locally, then confirm Nginx is forwarding requests correctly.

sudo systemctl status tomcat
sudo ss -tlnp | grep 8080
curl -I http://127.0.0.1:8080
curl -I http://example.com/demo/

You should see an HTTP 200 response from the curl request against your domain, and the demo page content should load in a browser.

Common issues

SymptomCauseFix
502 Bad Gateway from NginxTomcat is not running or not listening on 8080Run sudo systemctl status tomcat and check /opt/tomcat/logs/catalina.out
Tomcat service fails with status 203/EXECWrong JAVA_HOME path or script not executableVerify the path with sudo alternatives --config java, see the 203/EXEC fix guide
403 Forbidden on manager appNo roles configured in tomcat-users.xmlAdd a manager-gui role and user, then restart Tomcat
Nginx returns 404 for deployed appWrong context path or app not deployedConfirm the folder exists under /opt/tomcat/webapps and matches the URL path
Port 8080 reachable from the internetFirewall allows all ports by defaultRestrict inbound rules to 22, 80 and 443 only

Next steps

Running this in production?

Want this handled for you? This works for a single server. When you run multiple environments or need this available 24/7, keeping Java updated, Tomcat patched, and Nginx tuned is a different job. See how we run infrastructure like this for European teams.
#tomcat #apache tomcat #nginx #reverse proxy #java #systemd #web server #beginner

Don't want to manage this yourself?

We handle infrastructure for businesses that depend on uptime. Fully managed, with one fixed contact who knows your setup.

You get one fixed contact who knows your setup

At their desk in Rotterdam 12:42 · reachable in a message, no ticket form

Learn more: managed cloud infrastructure