Master Tomcat: Install, Configure, and Integrate with Nginx on Linux
This guide walks you through Tomcat’s overview, multiple installation methods, essential configuration files, port settings, virtual‑host setup, and how to combine Tomcat with Nginx for static‑dynamic separation, providing a complete Linux‑based deployment workflow.
Tomcat
Overview
Tomcat is a free open‑source lightweight web application server written in Java, widely used for development and debugging of JSP programs 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
# cd /usr/local/tomcat
# /usr/local/tomcat/bin/startup.sh
# /usr/local/tomcat/bin/shutdown.sh
# 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 tomcatConfiguration files and core components
bin : startup and shutdown scripts (catalina.sh, startup.sh, shutdown.sh).
conf : main configuration files (server.xml, context.xml, tomcat-users.xml, web.xml).
lib : JAR libraries.
logs : log files (catalina.out).
temp : temporary files.
webapps : deployed web applications.
work : work directory for compiled JSPs.
conf sub‑directory files
server.xml : global server configuration.
web.xml : default deployment descriptor for all webapps.
context.xml : default Context configuration for all webapps.
tomcat-users.xml : user authentication.
catalina.policy : security policy.
catalina.properties : environment variables and JVM tuning.
logging.properties : logging configuration.
Tomcat ports
8080 – HTTP port.
8005 – Shutdown port.
8009 – AJP connector.
Virtual host configuration
# mkdir -p /data/web{1,2,3}/ROOT/ -pv
# 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/Tomcat + Nginx static‑dynamic separation
# 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;
}Access Tomcat web pages via IP address and port:
Illustration of Nginx reverse‑proxy configuration:
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
