Tomcat is still the servlet container most enterprise Java apps target, and it is still ten years’ worth of installer cruft that needs cleaning up before a fresh install is production-ready. This article installs Tomcat 10 on Ubuntu with a tomcat service user, points it at a JDK, secures the manager interface, and puts Nginx in front so the public-facing TLS lives somewhere sensible.
How to verify
Inspect what is installed and listening:
java -version
systemctl status tomcat --no-pager | head 2>/dev/null
ls /opt/tomcat/ /var/lib/tomcat/ 2>/dev/null
sudo ss -lntp | grep -E ':8080|:8443|:8005'
ls /etc/systemd/system/tomcat*.service 2>/dev/null
Port 8005 is Tomcat’s shutdown port — if it is reachable from outside, that is a problem. Tomcat will shut itself down if it receives the configured shutdown password on that socket.
What’s happening
Tomcat ships as a directory of scripts (bin/catalina.sh), config (conf/server.xml, conf/web.xml), and a place to put webapps (webapps/). A .war dropped into webapps/ is auto-deployed by the host; an exploded directory works too. Tomcat 10 moved to the jakarta.* package namespace (from javax.*), so apps compiled for Tomcat 9 will not run on 10 without recompilation.
The standard production layout uses a dedicated tomcat system user that owns the install directory and runs the process. Tomcat does not need root; it should never run as root. The “shutdown port” (8005 by default) is a remnant of the script-based shutdown mechanism — disable it (port="-1") once you switch to systemd-driven lifecycle.
Tomcat has a built-in HTTP connector (port 8080) and a TLS connector if you configure one. In practice, terminate TLS at Nginx, proxy plain HTTP to Tomcat over localhost — the certificate management is easier and Nginx handles slow clients better.
The procedure
-
Install a JDK and create the service user:
sudo apt update sudo apt install -y openjdk-21-jre-headless sudo adduser --system --shell /bin/false --group --no-create-home --home /opt/tomcat tomcat -
Download Tomcat. Take the version from the Apache mirror and check the signature/SHA:
TOMCAT=10.1.34 curl -sLO https://dlcdn.apache.org/tomcat/tomcat-10/v${TOMCAT}/bin/apache-tomcat-${TOMCAT}.tar.gz curl -sLO https://dlcdn.apache.org/tomcat/tomcat-10/v${TOMCAT}/bin/apache-tomcat-${TOMCAT}.tar.gz.sha512 sha512sum -c apache-tomcat-${TOMCAT}.tar.gz.sha512 sudo tar -xzf apache-tomcat-${TOMCAT}.tar.gz -C /opt/ sudo ln -sf /opt/apache-tomcat-${TOMCAT} /opt/tomcat sudo chown -R tomcat:tomcat /opt/apache-tomcat-${TOMCAT} -
Lock down
conf/server.xml. Disable the shutdown port and bind the HTTP connector to localhost:<Server port="-1" shutdown="SHUTDOWN"> <!-- ... --> <Service name="Catalina"> <Connector port="8080" protocol="HTTP/1.1" address="127.0.0.1" connectionTimeout="20000" maxThreads="200" redirectPort="8443" /> <!-- ... --> </Service> </Server>address="127.0.0.1"prevents anything other than the local Nginx from reaching Tomcat. -
Secure the manager app. In
conf/tomcat-users.xml, add amanager-gui/manager-scriptrole and a strong password — or remove themanagerandhost-managerdirectories fromwebapps/entirely if you do not need them. Most production deploys do not.sudo rm -rf /opt/tomcat/webapps/manager /opt/tomcat/webapps/host-manager sudo rm -rf /opt/tomcat/webapps/examples /opt/tomcat/webapps/docs -
systemd unit at
/etc/systemd/system/tomcat.service:[Unit] Description=Apache Tomcat After=network.target [Service] Type=forking User=tomcat Group=tomcat Environment=JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat Environment=CATALINA_BASE=/opt/tomcat Environment="CATALINA_OPTS=-XX:MaxRAMPercentage=75.0 -XX:+UseG1GC" ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/opt/tomcat/bin/shutdown.sh Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target -
Enable, start, drop a WAR:
sudo systemctl daemon-reload sudo systemctl enable --now tomcat sudo cp app.war /opt/tomcat/webapps/ # auto-deploys to /app context curl http://127.0.0.1:8080/app/ -
Nginx in front:
server { listen 443 ssl http2; server_name app.example.com; # ssl_certificate ... ssl_certificate_key ... location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; } }Configure Tomcat’s
RemoteIpValveinserver.xmlso the app sees the real client IP fromX-Forwarded-For, not Nginx’s localhost.
Operational notes
<Connector ... protocol="org.apache.coyote.http11.Http11Nio2Protocol">switches to the NIO.2 connector — better for high concurrency with mostly-idle keep-alive connections. Defaults differ across Tomcat versions; specify explicitly in production.setenv.shinbin/is read by Tomcat scripts and is the right place forCATALINA_OPTS. systemdEnvironment=overrides work too; pick one location.- Tomcat’s
access_logvalve writes tologs/localhost_access_log.YYYY-MM-DD.txt. Disable it if Nginx is logging the same requests — duplicated logs eat disk and clutter analysis. - Tomcat ships with an SSL connector commented out. Use it only if Tomcat is internet-facing; for the proxy pattern, leave it disabled and let Nginx terminate TLS.
- For deploying via WAR drops,
autoDeploy="false"anddeployOnStartup="false"on the<Host>plus an explicitManagerdeploy via the script API give you transactional deploys instead of “drop and pray”.
For JVM tuning that backs Tomcat, see JVM tuning for production. Stack Harbor’s managed operations practice runs Tomcat behind Nginx with the manager apps removed and a dedicated user — the Tomcat install that ships with vendor demos is the one most often compromised in the wild, and the trim is the easiest hardening win.