Configuration of Apache Tomcat
1. What is Apache Tomcat?
Apache Tomcat is an open-source servlet container / JSP engine that implements the Java Servlet, JSP, EL and WebSocket specifications. It can act as a standalone web server (HTTP connector) or behind Apache/IIS/Nginx (AJP connector), executing Java web applications (WARs).
2. Tomcat Directory Structure
| Directory | Contents |
|---|---|
bin/ |
Startup/shutdown scripts — startup.bat/.sh, shutdown.bat/.sh, catalina.bat/.sh |
conf/ |
server.xml (main config), web.xml (default web-app), context.xml, tomcat-users.xml (manager roles), catalina.policy |
logs/ |
catalina.out, localhost access logs |
webapps/ |
Deployed web applications — each as a directory or a WAR file |
work/ |
Compiled JSP → servlet classes (temporary) |
temp/, lib/ |
Temp files, shared JARs |
A web-app layout inside webapps/myapp: WEB-INF/web.xml (deployment descriptor), WEB-INF/classes/ (servlet classes), WEB-INF/lib/ (JARs), plus JSP/HTML/CSS/JS.
3. conf/server.xml — Key Elements
<Server port="8005" shutdown="SHUTDOWN"> <!-- admin shutdown listener -->
<Service name="Catalina">
<!-- HTTP connector: browsers talk here (default 8080) -->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000" maxThreads="200"
redirectPort="8443" />
<!-- AJP connector: Apache mod_jk/mod_proxy_ajp talks here -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm ... /> <!-- users/roles (tomcat-users.xml, JDBC, LDAP) -->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/myapp" docBase="myapp"
reloadable="true" /> <!-- one web-app context -->
</Host>
</Engine>
</Service>
</Server>
Processing chain: Connector → Engine → Host → Context → Wrapper(servlet), with Valves as interceptors (logging/access) and a thread pool (maxThreads) per connector.
4. Common Configuration Tasks
- Change the port — edit
<Connector port="8080">→80; the shutdown port (8005) must also differ from other Tomcats on the box. - Deploy an application
- Copy
myapp.warintowebapps/(auto-unpack & deploy), or - Create
webapps/myapp/directory, or - Add a
<Context>element /myapp.xmlinconf/Catalina/localhost/, or - Use the Manager App (
http://localhost:8080/manager/html) — deploy/reload/stop/start/undeploy.
- Copy
- Manager access — add to
conf/tomcat-users.xml:
<user username="admin" password="secret" roles="manager-gui,admin-gui"/>
- Enable SSL (HTTPS) — generate a keystore (
keytool -genkey -alias tomcat -keystore .keystore), then a connector on 8443:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
SSLEnabled="true" scheme="https" secure="true"
keystoreFile=".keystore" keystorePass="changeit" />
- Virtual hosts — extra
<Host name="www.shop.com" appBase="/var/webapps">+ DNS entry. - JNDI DataSource (DB pooling) —
<Resource name="jdbc/shopDB" auth="Container" type="javax.sql.DataSource" .../>incontext.xml. - Memory tuning —
set JAVA_OPTS=-Xms512m -Xmx1024mincatalina.bat/.sh; threads via connectormaxThreads; session timeout viaweb.xml<session-config><session-timeout>30</...>. - Logging —
conf/logging.properties; access log Valve on the Host. - Start/stop —
bin/startup.sh(or.bat) /bin/shutdown.sh; verify athttp://localhost:8080.
5. Tomcat as a Component of the Web
Browser --HTTP--> Apache (mod_proxy_ajp) --AJP 8009--> Tomcat --> Servlet/JSP --> DB
Browser -----------------HTTP 8080---------------------> Tomcat (standalone)
6. Exam Points
- Explain the Tomcat directory structure and the role of
server.xmlwith its connector/engine/host/context elements — 10 marks (very frequent). - List the steps to deploy a web application in Tomcat (WAR, directory, Manager App) — 7 marks.
- Write the configuration for changing the port / enabling SSL / adding a manager user — 5-7 marks.
- Short note: Tomcat vs Apache HTTP Server (web container vs web server) — 5 marks.