在 CentOS 上查看 Apache 日志,通常分为 访问日志(access log) 和 错误日志(error log),位置取决于你是用哪种方式安装的 Apache(yum 安装还是源码安装)。
systemctl status httpd
或
ps aux | grep httpd
/var/log/httpd/error_log
查看方式:
tail -f /var/log/httpd/error_log
-f表示实时查看最新日志
/var/log/httpd/access_log
查看方式:
tail -f /var/log/httpd/access_log
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
tail -n 100 /var/log/httpd/access_log
grep "404" /var/log/httpd/access_log
grep -i "error" /var/log/httpd/error_log
less /var/log/httpd/error_log
按
G跳到末尾,q退出
日志一般在:
/usr/local/apache/logs/error_log
/usr/local/apache/logs/access_log
CentOS 默认会轮转 Apache 日志:
/etc/logrotate.d/httpd
如果你能告诉我:
我可以给你更精准的命令。