查看 Apache 访问日志的方法取决于你的操作系统和 Apache 配置,下面是最常见的几种方式。
/var/log/apache2/access.log
/var/log/httpd/access_log
C:\Apache24\logs\access.log
(路径取决于 Apache 安装位置)
tail -f /var/log/apache2/access.log
tail -n 100 /var/log/apache2/access.log
less /var/log/apache2/access.log
grep "1.2.3.4" /var/log/apache2/access.log
grep "10/Jan/2026" /var/log/apache2/access.log
如果你不确定日志在哪,可以查 Apache 配置:
apachectl -S
或查看配置文件:
grep -R "CustomLog" /etc/apache2/
# 或
grep -R "CustomLog" /etc/httpd/
示例配置:
CustomLog ${APACHE_LOG_DIR}/access.log combined
默认 combined 格式示例:
192.168.1.10 - - [10/Jan/2026:12:34:56 +0800] "GET /index.html HTTP/1.1" 200 1234 "http://example.com/" "Mozilla/5.0"
字段含义:
grep " 404 " /var/log/apache2/access.log
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head
grep -i "bot\|spider\|crawl" /var/log/apache2/access.log
systemctl status apache2
ls -ld /var/log/apache2
systemctl restart apache2
如果你愿意,可以告诉我:
我可以给你更精确的命令。