温馨提示×

centos如何查看apache日志

小樊
44
2026-09-12 01:16:13
栏目: 智能运维

在 CentOS 上查看 Apache 日志,通常分为 访问日志(access log)错误日志(error log),位置取决于你是用哪种方式安装的 Apache(yum 安装还是源码安装)。


一、确认 Apache 是否运行

systemctl status httpd

ps aux | grep httpd

二、常见日志路径(CentOS + yum 安装 Apache)

1. 错误日志

/var/log/httpd/error_log

查看方式:

tail -f /var/log/httpd/error_log

-f 表示实时查看最新日志

2. 访问日志

/var/log/httpd/access_log

查看方式:

tail -f /var/log/httpd/access_log

三、如果找不到日志位置

方法 1:查看 Apache 配置文件

grep -R "ErrorLog" /etc/httpd/
grep -R "CustomLog" /etc/httpd/

常见结果:

ErrorLog logs/error_log
CustomLog logs/access_log combined

相对路径是基于 /etc/httpd/ 的,即: /etc/httpd/logs/error_log (通常是软链接到 /var/log/httpd/


四、常用查看命令

实时查看日志

tail -f /var/log/httpd/error_log

查看最后 100 行

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

搜索关键字(如 404、error)

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

按时间排序查看

less /var/log/httpd/error_log

G 跳到末尾,q 退出


五、源码安装的 Apache(非 yum)

日志一般在:

/usr/local/apache/logs/error_log
/usr/local/apache/logs/access_log

六、日志轮转(logrotate)

CentOS 默认会轮转 Apache 日志:

/etc/logrotate.d/httpd

如果你能告诉我:

  • Apache 是怎么安装的(yum / 源码)
  • 想看错误日志还是访问日志
  • 是否遇到具体错误(如 403 / 500)

我可以给你更精准的命令。

0