在 CentOS 上查看 Apache 日志,通常是看 访问日志 和 错误日志,位置取决于你是用的 CentOS 自带 Apache(httpd) 还是 编译安装 的。
/var/log/httpd/
常见文件:
access_log :访问日志error_log :错误日志# 查看访问日志
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
grep ErrorLog /etc/httpd/conf/httpd.conf
grep CustomLog /etc/httpd/conf/httpd.conf
常见路径:
/usr/local/apache/logs/
或
/usr/local/httpd/logs/
查看方式相同:
tail -f /usr/local/apache/logs/error_log
如果是 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
如果你愿意,可以告诉我:
yum 还是源码安装我可以给你更精确的命令。