温馨提示×

centos怎么查看apache日志

小樊
44
2026-09-09 00:05:36
栏目: 智能运维

在 CentOS 上查看 Apache 日志,通常是看 访问日志错误日志,位置取决于你是用的 CentOS 自带 Apache(httpd) 还是 编译安装 的。


一、CentOS 自带 Apache(yum 安装,服务名 httpd)

1. 日志默认位置

/var/log/httpd/

常见文件:

  • access_log :访问日志
  • error_log :错误日志

2. 查看日志

# 查看访问日志
tail -f /var/log/httpd/access_log

# 查看错误日志
tail -f /var/log/httpd/error_log

# 查看最后 100 行
tail -n 100 /var/log/httpd/error_log

# 实时查看(推荐)
tail -f /var/log/httpd/access_log

3. 查找日志路径(确认)

grep ErrorLog /etc/httpd/conf/httpd.conf
grep CustomLog /etc/httpd/conf/httpd.conf

二、如果你用的是 Apache(源码安装)

常见路径:

/usr/local/apache/logs/

/usr/local/httpd/logs/

查看方式相同:

tail -f /usr/local/apache/logs/error_log

三、用 journalctl(系统日志,部分情况)

如果是 systemd 管理的 httpd:

journalctl -u httpd
journalctl -u httpd -f

四、常用排查技巧

# 查看 404 请求
grep " 404 " /var/log/httpd/access_log

# 查看某 IP 访问
grep "192.168.1.100" /var/log/httpd/access_log

# 查看错误日志中的 Error
grep -i error /var/log/httpd/error_log

如果你愿意,可以告诉我:

  • CentOS 版本(6 / 7 / 8 / Stream)
  • Apache 是 yum 还是源码安装
  • 想查“访问异常”还是“启动报错”

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

0