> 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/di-36-zhang-web-fu-wu-qi/di-36.5-jie-tomcat-ying-yong-fu-wu-qi.md).

# 36.5 Tomcat 应用服务器

本节介绍在 FreeBSD 操作系统上部署 Tomcat 应用服务器的方法。

## 安装 Tomcat

使用 pkg 包管理器安装：

```sh
# pkg install tomcat110
```

如果使用 Ports 方式安装：

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

## 配置 Tomcat

Tomcat 11 的安装目录位于 **/usr/local/apache-tomcat-11.0**。

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

其主要目录结构：

| 目录         | 说明                                                                                                      |
| ---------- | ------------------------------------------------------------------------------------------------------- |
| `bin/`     | 存放启动、停止等脚本文件                                                                                            |
| `conf/`    | 存放配置文件，包括 `server.xml`（主配置文件，由 `server.xml.sample` 复制而来）和 `web.xml`（Web 应用默认配置，由 `web.xml.sample` 复制而来） |
| `webapps/` | Web 应用部署目录                                                                                              |
| `logs/`    | 日志文件目录                                                                                                  |
| `work/`    | JSP 编译后的临时工作目录                                                                                          |

### Tomcat 服务

添加至启动项，设置 Tomcat 服务开机自启：

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

启动 Tomcat 服务：

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

打开 `ip:8080`，如 `http://192.168.179.150:8080/`，可访问 Tomcat 的默认页面：

> **技巧**
>
> 上述示例中的 **192.168.179.150** 为占位符，需要替换为实际的值。

![Tomcat FreeBSD](/files/uouhusflJAP697Fhm51d)

### 基础配置说明

Tomcat 的主要配置文件为 **/usr/local/apache-tomcat-11.0/conf/server.xml**，该文件定义了服务端口、连接器、引擎和主机等核心组件。默认情况下，Tomcat 监听 8080 端口用于 HTTP 连接。AJP（Apache JServ Protocol）连接器默认未启用，如需使用可在 `server.xml` 中取消注释以启用 8009 端口。如需修改端口或配置 HTTPS 支持，可编辑该配置文件。

Web 应用应部署在 **/usr/local/apache-tomcat-11.0/webapps/** 目录下，Tomcat 会自动加载该目录下的 WAR 包或解压后的 Web 应用目录。

* Apache Software Foundation. Apache Tomcat 11 Configuration Reference\[EB/OL]. \[2026-04-17]. <https://tomcat.apache.org/tomcat-11.0-doc/config/index.html>，Tomcat 11 各组件配置参考。
* Apache Software Foundation. Apache Tomcat 11 Migration Guide\[EB/OL]. \[2026-04-17]. <https://tomcat.apache.org/migration-11.0.html>，详述 Tomcat 11 所实现的 Jakarta EE 规范版本及从旧版本迁移的注意事项。


---

# 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, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/di-36-zhang-web-fu-wu-qi/di-36.5-jie-tomcat-ying-yong-fu-wu-qi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
