24.1 Apache Web 服务器
Apache HTTP Server 是全球使用最广泛的 Web 服务器之一,采用模块化架构,可通过动态加载扩展模块增强网站功能。本节涵盖 Ports 方式编译安装及基础配置。
24.1.1 安装 Apache
使用 Ports 方式安装:
sh
# cd /usr/ports/www/apache24/
# make install clean或使用 pkg 包管理器安装:
sh
# pkg install apache24安装完成后,查看安装包的说明文档,了解必要的配置和注意事项。
sh
# pkg info -D apache2424.1.2 守护进程
要让 Apache 在系统启动时自动运行,需配置为开机自启服务。
添加服务开机自启:
sh
# service apache24 enable # 设置 Apache HTTP Server 2.4 在系统启动时自动启动24.1.3 启动 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 服务是否正常响应请求:

24.1.4 附录:Apache 相关文件路径
以下是 Apache 在 FreeBSD 系统中的主要文件和目录路径,供配置和维护时参考。
目录结构:
text
/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/
24.1.5 参考文献
- 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 版本新特性与变更说明。