在 Debian 上,Apache 日志通常位于:
/var/log/apache2/access.log/var/log/apache2/error.log“过滤”日志常见有几种场景,下面按最常用方式说明。
grep "192.168.1.100" /var/log/apache2/access.log
grep "/index.php" /var/log/apache2/access.log
grep " 404 " /var/log/apache2/access.log
grep "PHP" /var/log/apache2/error.log
tail -f /var/log/apache2/access.log | grep "POST"
只看 POST 请求。
grep "$(date +%d/%b/%Y)" /var/log/apache2/access.log
grep "10/Oct/2024" /var/log/apache2/access.log
Apache 默认日志格式示例:
192.168.1.1 - - [10/Oct/2024:12:00:00 +0000] "GET / HTTP/1.1" 200 1234
awk '$9 != 200' /var/log/apache2/access.log
awk '{print $9}' /var/log/apache2/access.log | sort | uniq -c | sort -nr
Debian 默认会压缩旧日志:
zcat /var/log/apache2/access.log.1.gz | grep "error"
apt install goaccess
goaccess /var/log/apache2/access.log
apt install apachetop
apachetop -f /var/log/apache2/access.log
你可以告诉我:
我可以直接给你精确命令。