> 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.1-jie-apache-web-fu-wu-qi.md).

# 36.1 Apache Web 服务器

Apache HTTP Server 是全球使用最广泛的 Web 服务器之一，采用模块化架构，可通过动态加载扩展模块增强网站功能。本节涵盖 Ports 方式编译安装与基础配置。

## 安装 Apache

使用 Ports 方式安装：

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

或使用 pkg 包管理器安装：

```sh
# pkg install apache24
```

安装完成后，查看安装包的说明文档，了解必要的配置和注意事项。

```sh
# pkg info -D apache24
```

## 守护进程

若要使 Apache 在系统启动时自动运行，需将其配置为开机自启服务。

设置 Apache 服务开机自启：

```sh
# service apache24 enable   # 设置 Apache HTTP Server 2.4 在系统启动时自动启动
```

## 启动 Apache

完成开机自启配置后，可手动启动 Apache 服务，检查其运行状态。

启动服务：

```sh
# service apache24 start   # 启动 Apache HTTP Server 2.4 服务
Performing sanity check on apache24 configuration:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 198.18.0.103. Set the 'ServerName' directive globally to suppress this message
Syntax OK
Starting apache24.
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 198.18.0.103. Set the 'ServerName' directive globally to suppress this message
```

查看 Apache HTTP Server 2.4 服务状态：

```sh
# service apache24 status
apache24 is running as pid 2068.
```

Apache 服务启动后，可通过访问 `localhost` 或对应的 IP 地址验证 Web 服务是否正常响应请求：

![Apache FreeBSD](/files/2StgXEB4HJ2olymj1iDS)

## 附录：Apache 相关文件路径

以下是 Apache 在 FreeBSD 系统中的主要文件和目录路径，供配置和维护时参考。

目录结构：

```sh
/usr/local/
├── etc/
│   └── apache24/
│       ├── httpd.conf          # Apache 主配置文件（实际生效的配置）
│       └── httpd.conf.sample   # 示例配置文件（参考模板，不直接使用）
└── www/
    └── apache24/
        └── data/               # 网站根目录（存放网页内容，如 index.html）
```

说明：

* Apache 配置文件位于 **/usr/local/etc/apache24/httpd.conf**
* Apache 示例文件位于 **/usr/local/etc/apache24/httpd.conf.sample**
* Apache 网站根目录位于 **/usr/local/www/apache24/data/**

## 参考文献

* The Apache Software Foundation. Apache HTTP Server Documentation\[EB/OL]. \[2026-04-14]. <https://httpd.apache.org/docs/2.4/>. Apache HTTP Server 官方文档，涵盖配置指令、模块与虚拟主机。
* The Apache Software Foundation. Apache HTTP Server 2.4 Release Notes\[EB/OL]. \[2026-04-14]. <https://httpd.apache.org/docs/2.4/new_features_2_4.html>. Apache 2.4 版本新特性与变更说明。


---

# 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.1-jie-apache-web-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.
