36.1 Apache Web 服务器
Apache HTTP Server 是全球使用最广泛的 Web 服务器之一,采用模块化架构,可通过动态加载扩展模块增强网站功能。本节涵盖 Ports 方式编译安装与基础配置。
安装 Apache
使用 Ports 方式安装:
# cd /usr/ports/www/apache24/
# make install clean或使用 pkg 包管理器安装:
# pkg install apache24安装完成后,查看安装包的说明文档,了解必要的配置和注意事项。
# pkg info -D apache24守护进程
若要使 Apache 在系统启动时自动运行,需将其配置为开机自启服务。
设置 Apache 服务开机自启:
# service apache24 enable # 设置 Apache HTTP Server 2.4 在系统启动时自动启动启动 Apache
完成开机自启配置后,可手动启动 Apache 服务,检查其运行状态。
启动服务:
查看 Apache HTTP Server 2.4 服务状态:
Apache 服务启动后,可通过访问 localhost 或对应的 IP 地址验证 Web 服务是否正常响应请求:

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