在 Debian 上,Apache 日志通常位于:
/var/log/apache2/access.log/var/log/apache2/error.log“过滤日志内容”常见有几种场景,下面按用途给你示例。
grep "192.168.1.100" /var/log/apache2/access.log
grep "/login.php" /var/log/apache2/access.log
grep " 404 " /var/log/apache2/access.log
grep -i "php" /var/log/apache2/error.log
grep "10/Apr/2024" /var/log/apache2/access.log
grep "10/Apr/2024:10:" /var/log/apache2/access.log
awk '$9 == 500' /var/log/apache2/access.log
awk '{print $9}' /var/log/apache2/access.log | sort | uniq -c | sort -nr
awk '{print $1}' /var/log/apache2/access.log | sort | uniq -c | sort -nr | head
tail -f /var/log/apache2/access.log | grep "192.168.1.100"
goaccess(实时可视化)sudo apt install goaccess
goaccess /var/log/apache2/access.log
apachetopsudo apt install apachetop
apachetop -f /var/log/apache2/access.log
旧日志可能是:
/var/log/apache2/access.log.1
/var/log/apache2/access.log.2.gz
查看压缩日志:
zcat /var/log/apache2/access.log.2.gz | grep "404"
如果你能说清楚想过滤什么内容(比如:某 IP、某接口、错误类型、爬虫、攻击请求),我可以直接给你一条最合适命令。