Master Tomcat: Step‑by‑Step Installation, Configuration, and Nginx Integration
This guide walks you through installing Tomcat via yum or binary packages, configuring its core directories and ports, setting up virtual hosts, and integrating Tomcat with Nginx for static‑dynamic separation, providing complete commands and explanations for a production‑ready Java web server on Linux.
Tomcat
Overview
Tomcat is a free open‑source web application server written in Java, lightweight and commonly used for developing and debugging JSP programs, especially in small‑to‑medium systems.
Installation
1. Install via yum
# yum install tomcat* -y2. Binary installation
Install JDK first
# rpm -ivh jdk-8u201-linux-x64.rpm
# export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
# export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
# export PATH=$JAVA_HOME/bin:$PATH
# tar zxvf apache-tomcat-9.0.16.tar.gz
# cp -r apache-tomcat-9.0.16 /usr/local/tomcat
# useradd -s /sbin/nologin tomcat
# chown tomcat:tomcat /usr/local/tomcat -R
# cat > /usr/lib/systemd/system/tomcat.service <<EOF
[Unit]
Description=Tomcat
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
RestartSec=3
PrivateTmp=true
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
EOF
# systemctl daemon-reload
# systemctl start tomcat.serviceAfter starting, Tomcat listens on ports 8080 (HTTP), 8005 (shutdown), and 8009 (AJP).
Configuration files and core components
Directory
Function
bin
Startup and shutdown scripts such as catalina.sh, startup.sh, shutdown.sh
conf
Configuration files like server.xml, context.xml, tomcat-users.xml, web.xml
lib
Jar libraries; usually unchanged unless adding third‑party libs
logs
Log files, e.g., catalina.out
temp
Temporary files generated at runtime
webapps
Deployed web application resources
work
Work directory, often cleared when upgrading
conf sub‑directory files
File
Description
server.xml
Main global configuration
web.xml
Default deployment configuration for all webapps; can be overridden per app
context.xml
Default Context configuration for all webapps; can be overridden per app
tomcat-users.xml
User authentication accounts and passwords
catalina.policy
Security policy when Tomcat is started with security option
catalina.properties
Environment variables, classloader paths, JVM tuning parameters
logging.properties
Log system configuration (levels, paths)
Port numbers
8080 – default HTTP port
8005 – shutdown port
8009 – AJP connector for Apache integration
Virtual host configuration
# Create directories for each virtual host
mkdir -pv /data/web{1,2,3}/ROOT/
echo web1 > /data/web1/ROOT/index.html
echo web2 > /data/web2/ROOT/index.html
echo web3 > /data/web3/ROOT/index.html
chown -R tomcat.tomcat /data/Verify with curl:
# curl www.a.com:8080 # returns web1
# curl www.b.com:8080 # returns web2
# curl www.c.com:8080 # returns web3Tomcat and Nginx static‑dynamic separation
Install and configure Nginx, then proxy JSP requests to Tomcat while serving static files directly.
# Stop firewall
systemctl stop firewalld.service
setenforce 0
# Install EPEL and Nginx
yum install epel-release.noarch -y
yum install nginx -y
# Edit /etc/nginx/nginx.conf
upstream web {
server 192.168.10.40;
server 192.168.10.50;
}
location / {
proxy_pass http://web;
}
location ~\.jsp$ {
proxy_pass http://192.168.10.60:8080;
}
location ~\.(jpg|html)$ {
root /usr/share/nginx/html;
}Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
