温馨提示×

怎样查看centos apache日志

小樊
39
2026-09-02 22:27:16
栏目: 智能运维

在 CentOS 上查看 Apache 日志,通常步骤如下:

一、确认 Apache 是否已安装并运行

systemctl status httpd

(CentOS 中 Apache 服务名一般是 httpd

如果未运行,可启动:

systemctl start httpd

二、Apache 日志默认位置

CentOS 下 Apache 日志通常在:

/var/log/httpd/

常见日志文件:

  • 访问日志/var/log/httpd/access_log
  • 错误日志/var/log/httpd/error_log

三、查看日志的常用命令

1. 查看错误日志(实时)

tail -f /var/log/httpd/error_log

2. 查看访问日志(实时)

tail -f /var/log/httpd/access_log

3. 查看最近 100 行

tail -n 100 /var/log/httpd/error_log

4. 搜索关键字(如 404、error)

grep "404" /var/log/httpd/access_log
grep "error" /var/log/httpd/error_log

5. 查看日志配置(确认路径)

grep -i "log" /etc/httpd/conf/httpd.conf

或虚拟主机配置:

grep -ri "log" /etc/httpd/conf.d/

四、如果是 SELinux 导致无法写日志

可查看:

getsebool -a | grep httpd

五、使用 journalctl(系统日志)

有些错误也会记录在系统日志:

journalctl -u httpd

如果你用的是 CentOS 8+ / StreamApache + PHP / Nginx 反代,日志位置可能不同,可以告诉我你的具体环境,我可以给你更精确的命令。

0