Web 服务器把网页送给浏览器。装 Apache httpd、改 DocumentRoot、apachectl configtest 校验、放行 http。
Web 服务器把网页送给浏览器。RHEL 系默认 Apache(软件包 httpd)。教材项目 11。
dnf install -y httpd;守护进程 httpd,管理命令 apachectl。
关键指令:Listen 80、ServerName、DocumentRoot "/var/www/html"(网页根)、DirectoryIndex index.html。网页放 DocumentRoot 即可访问。
关键指令:<code>Listen 80</code>、<code>ServerName</code>、<code>DocumentRoot "/var/www/html"</code>(网页根)、<code>DirectoryIndex index.html</code>。网页放 DocumentRoot 即可访问。启动服务并设置开机自启;用 firewall-cmd --add-service=http --permanent 放行,再 --reload。生产服务器只开必要端口。
systemctl enable --now http
firewall-cmd --add-service=http --permanent
firewall-cmd --reload在 /var/www/html 放一个 index.html,浏览器访问 http://服务器IP 应看到页面;curl -I localhost 返回 200 即正常。
apachectl configtest 校验配置语法apachectl start/stop/restartapachectl -S 看虚拟主机与端口httpd -t 等价 configtestfirewall-cmd --add-service=http --permanentfirewall-cmd --add-service=https --permanentsystemctl enable --now httpdcurl -I localhost 看响应头验证systemctl status 确认 Active(running)。firewall-cmd --add-service=http --permanent 放行后 --reload,从另一台机器测试能连通。systemctl enable),重启虚拟机验证自动起来。服务项目重在『排障』:连不上时按 配置→端口→防火墙→日志 逐层查,journalctl -u 服务名 是第一现场。