Open In App

Apache Tomcat Configuration Files

Last Updated : 11 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Apache Tomcat uses a set of core configuration files to manage server behavior, application deployment, user access, and resource integration. Located in the conf/ directory, these files define key components such as ports, connectors, servlet mappings, security roles, and logging levels.

Understanding these files like server.xml, context.xml, web.xml, and tomcat-users.xml is essential for customizing Tomcat in development or production environments. Here, we covers their purpose, location, and configuration with practical examples.

Tomcat Directory Structure

After installation (e.g., in /opt/tomcat), the typical directory layout looks like:

/opt/tomcat
├── bin/ # Scripts to start/stop Tomcat
├── conf/ # All main configuration files
├── webapps/ # Deployed apps (WAR files or folders)
├── logs/ # Log output (catalina.out, etc.)
├── lib/ # Java libraries used by Tomcat
├── temp/, work/, etc.

Key Configuration Files and Their Purpose

key_configuration_files

1. server.xmlMain Tomcat Configuration

  • Path: /opt/tomcat/conf/server.xml
  • Purpose: This is the core file that defines how Tomcat runs: its ports, services, connectors, and virtual hosts.

Key Elements:

  • <Connector>: Defines how Tomcat accepts HTTP/HTTPS requests.
  • <Host>: Lets you host multiple applications (or domains) on the same server.
  • <Engine> and <Service>: Control overall server behavior and how requests are processed.

Example: Change Default HTTP Port

<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
  • This changes the HTTP port from 8080 to 8081.
  • Access the app at http://localhost:8081 instead of 8080.

Note: Restart Tomcat for changes to take effect.

2. context.xmlGlobal or Application Context Settings

Tomcat uses this file to define environment-specific settings like JNDI resources (databases, caches, etc.).

Paths:

  • Global Context: /opt/tomcat/conf/context.xml
  • Per-Application: yourapp/META-INF/context.xml

Used For:

  • Setting up JNDI resources (e.g., database connections)
  • Defining environment variables
  • Enabling hot deployment during development

Example:

Add a MySQL resource:

<Context>
<Resource name="jdbc/mydb" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mydb"
username="root" password="password" />
</Context>

3. web.xml – Web Application Deployment Descriptor

This file defines how a web application behaves, such as URL mappings, servlets, filters, and default pages.

Paths:

  • Global: /opt/tomcat/conf/web.xml (applies to all apps)
  • App-Specific: WEB-INF/web.xml

Used For:

  • Declaring servlets and their classes
  • Mapping URLs to servlets
  • Defining filters, listeners, error pages, and welcome files

Example: HelloServlet Mapping

<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>com.example.HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

Now, accessing http://localhost:8080/yourapp/hello invokes the HelloServlet.

Best practice: Define this in WEB-INF/web.xml to keep it app-specific.

4. tomcat-users.xmlTomcat User Access Control

  • Path: /opt/tomcat/conf/tomcat-users.xml
  • Purpose: Manage users and roles for accessing Tomcat’s Manager and Host Manager GUIs.

Example: Add Admin User

<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="admin" password="admin123" roles="manager-gui,admin-gui"/>
</tomcat-users>

Access the admin interface at:

  • http://localhost:8080/manager/html
  • http://localhost:8080/host-manager/html

Security Tip: Never use weak credentials in production. Always update the default passwords!

5. logging.propertiesLogging Configuration

  • Path: /opt/tomcat/conf/logging.properties
  • Purpose: Controls how Tomcat writes logs to /opt/tomcat/logs/.

Used For:

  • Setting log levels (INFO, DEBUG, WARNING, etc.)
  • Changing output format or destinations
  • Debugging specific Tomcat components

Example: Increase Logging for Catalina (Core Component)

org.apache.catalina.level = FINE

You will now see more detailed logs in /opt/tomcat/logs/catalina.out, which helps during debugging.


Article Tags :

Explore