推荐使用 dnf 安装:先启用 BaseOS 和 AppStream 仓库,执行 dnf update -y 和 dnf install -y httpd,再 systemctl enable --now httpd,配置防火墙放行 HTTP,并用 httpd -t 验证语法。
在 rhel 9 上安装 apache http server,推荐使用系统原生的 dnf 包管理器安装官方维护的稳定版本。截至 2026 年 9 月,rhel 9.6 默认仓库中提供的 httpd 版本为 2.4.57,已同步上游安全与功能更新,无需手动编译或引入第三方源。
确认系统环境与基础准备
确保系统已注册并启用订阅(尤其是 BaseOS 和 AppStream 仓库),否则 dnf install httpd 会失败:
- 检查仓库状态:
dnf repolist --enabled,应看到rhel-9-for-x86_64-baseos-rpms和rhel-9-for-x86_64-appstream-rpms - 若未启用,运行:
subscription-manager repos --enable=rhel-9-for-x86_64-baseos-rpms --enable=rhel-9-for-x86_64-appstream-rpms - 更新系统至最新状态:
dnf update -y,避免因旧内核或库引发兼容问题
安装与基础服务管理
直接安装官方 httpd 包,它已预集成常用模块(mod_ssl、mod_rewrite、mod_headers 等):
Apache Superset 是一个广泛采用的开源 BI 平台,用于 SQL 探索、图表构建和仪表板交付。当代理需要查询仓库数据、组装仪表板或使用成熟的分析界面解释指标而不是临时笔记本代码时,此技能非常有用。
- 执行安装:
dnf install -y httpd - 启动并设为开机自启:
systemctl enable --now httpd - 验证运行状态:
systemctl is-active httpd应返回active;ss -tlnp | grep :80可确认监听状态 - 默认首页位于
/var/www/html/index.html,浏览器访问服务器 IP 即可看到 RHEL 默认欢迎页
防火墙与SELinux适配
RHEL 9 默认启用 firewalld 和强制 SELinux,需显式放行并确认上下文:
- 开放 HTTP 服务:
firewall-cmd --permanent --add-service=http && firewall-cmd --reload - 如需 HTTPS,额外执行:
firewall-cmd --permanent --add-service=https && firewall-cmd --reload - SELinux 默认策略已允许
httpd访问标准 Web 目录,但若自定义网站路径(如/srv/www),需设置正确上下文:semanage fcontext -a -t httpd_sys_content_t "/srv/www(/.*)?" && restorecon -Rv /srv/www
验证与快速调试
安装完成后建议立即验证核心功能是否就绪:
- 检查主配置语法:
httpd -t,输出Syntax OK表示无误 - 查看已加载模块:
httpd -M | grep -E "(ssl|rewrite|headers)" - 日志位置:
/var/log/httpd/access_log和/var/log/httpd/error_log,权限为root:apache,普通用户需sudo查看 - 若页面无法访问,优先排查:
systemctl status httpd(是否有启动失败)、journalctl -u httpd -n 50 --no-pager(最近错误)、getenforce(是否为Enforcing且阻断了访问)

















