下面按常见 Linux 场景给你总结,怎么用命令查 Apache 日志。
常见路径:
/var/log/apache2/access.log # Debian/Ubuntu
/var/log/apache2/error.log
/var/log/httpd/access_log # CentOS/RHEL
/var/log/httpd/error_log
也可以通过配置确认:
apachectl -S
# 或
grep -R "CustomLog" /etc/apache2/
tail -f /var/log/apache2/access.log
tail -f /var/log/apache2/error.log
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head
grep "1.2.3.4" access.log
awk '$9 == 404' access.log
或
grep " 404 " access.log
grep " 500 " access.log
grep "/index.php" access.log
grep "10/Apr/2024" access.log
grep -i "error" error.log
grep -i "php" error.log
awk '{print $9}' access.log | sort | uniq -c | sort -nr
awk '{print $4}' access.log | cut -d: -f1-2 | sort | uniq -c
journalctl -u apache2 -f
journalctl -u httpd -f
如果你能告诉我:
我可以给你精确的命令。