在 CentOS 上查看 Apache(通常是 httpd)的配置,可以从以下几个方面入手:
CentOS 上 Apache 一般叫 httpd:
rpm -qa | grep httpd
# 或
which httpd
查看服务状态:
systemctl status httpd
CentOS 7/8/Stream 常见路径:
/etc/httpd/conf/httpd.conf # 主配置文件
/etc/httpd/conf.d/ # 额外配置文件(如 ssl.conf、virtual host)
查看主配置:
cat /etc/httpd/conf/httpd.conf
可用 grep 过滤:
grep -i "ServerRoot" /etc/httpd/conf/httpd.conf
grep -i "DocumentRoot" /etc/httpd/conf/httpd.conf
grep -i "Listen" /etc/httpd/conf/httpd.conf
Apache 启动时会加载:
Include 的 conf.d/*.conf查看被包含的文件:
grep -i "Include" /etc/httpd/conf/httpd.conf
列出所有配置:
ls -l /etc/httpd/conf.d/
修改配置后一定要测试:
httpd -t
# 或
apachectl configtest
输出 Syntax OK 表示正常。
如果 Apache 已启动,可查看编译参数和运行信息:
httpd -V
查看模块:
httpd -M
grep -i "VirtualHost" -R /etc/httpd/
或查看:
cat /etc/httpd/conf.d/*.conf
/var/log/httpd/access_log
/var/log/httpd/error_log
实时查看:
tail -f /var/log/httpd/error_log
如果你愿意,可以告诉我:
我可以给你更精准的命令。