> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/ask/flat/chapter-38-web-servers/di-38.5-jie-tomcat-ying-yong-fu-wu-qi.md).

# 38.5 Tomcat Application Server

This section describes how to deploy the Tomcat application server on the FreeBSD operating system.

## Installing Tomcat

Install using the pkg package manager:

```sh
# pkg install tomcat110
```

If installing using Ports:

```sh
# cd /usr/ports/www/tomcat110/
# make install clean
```

## Configuring Tomcat

The Tomcat 11 installation directory is located at **/usr/local/apache-tomcat-11.0**.

```sh
/usr/local/apache-tomcat-11.0/
├── bin/
├── conf/
│   ├── server.xml
│   └── web.xml
├── webapps/
├── logs/
└── work/
```

Its main directory structure:

| Directory  | Description                                                                                                                                                                                       |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `bin/`     | Stores startup, shutdown, and other script files                                                                                                                                                  |
| `conf/`    | Stores configuration files, including `server.xml` (main configuration file, copied from `server.xml.sample`) and `web.xml` (default web application configuration, copied from `web.xml.sample`) |
| `webapps/` | Web application deployment directory                                                                                                                                                              |
| `logs/`    | Log file directory                                                                                                                                                                                |
| `work/`    | Temporary working directory for compiled JSP files                                                                                                                                                |

### Tomcat Service

Add to startup items and set the Tomcat service to start at boot:

```sh
# service tomcat110 enable
tomcat110 enabled in /etc/rc.conf
```

Start the Tomcat service:

```sh
# service tomcat110 start
Starting tomcat110.
```

Open `ip:8080`, for example `http://192.168.179.150:8080/`, to access the Tomcat default page:

> **Tip**
>
> The **192.168.179.150** in the above example is a placeholder and needs to be replaced with the actual value.

![Tomcat FreeBSD](/files/Dj6wf4ziAMsUUkaBUJS1)

### Basic Configuration Notes

The main Tomcat configuration file is **/usr/local/apache-tomcat-11.0/conf/server.xml**, which defines core components such as service ports, connectors, engines, and hosts. By default, Tomcat listens on port 8080 for HTTP connections. The AJP (Apache JServ Protocol) connector is not enabled by default; if needed, uncomment it in `server.xml` to enable port 8009. To modify the port or configure HTTPS support, edit this configuration file.

Web applications should be deployed in the **/usr/local/apache-tomcat-11.0/webapps/** directory; Tomcat will automatically load WAR packages or unpacked web application directories under this directory.

* Apache Software Foundation. Apache Tomcat 11 Configuration Reference\[EB/OL]. \[2026-04-17]. <https://tomcat.apache.org/tomcat-11.0-doc/config/index.html>, Configuration reference for Tomcat 11 components.
* Apache Software Foundation. Apache Tomcat 11 Migration Guide\[EB/OL]. \[2026-04-17]. <https://tomcat.apache.org/migration-11.0.html>, Details the Jakarta EE specification version implemented by Tomcat 11 and notes for migrating from older versions.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.bsdcn.org/ask/flat/chapter-38-web-servers/di-38.5-jie-tomcat-ying-yong-fu-wu-qi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
