在 CentOS 上查看 Apache 访问日志,通常按下面几个步骤来即可。
systemctl status httpd
如果未运行,可启动:
systemctl start httpd
在 CentOS(使用 httpd)中,默认访问日志一般位于:
/var/log/httpd/access_log
错误日志在:
/var/log/httpd/error_log
如果你用的是 源码安装或自定义配置,路径可能不同,可查看配置文件确认。
grep -R "CustomLog" /etc/httpd/conf/httpd.conf
或查看虚拟主机配置:
grep -R "CustomLog" /etc/httpd/conf.d/
tail -f /var/log/httpd/access_log
按 Ctrl + C 退出
tail -n 100 /var/log/httpd/access_log
head -n 50 /var/log/httpd/access_log
grep "192.168.1.100" /var/log/httpd/access_log
awk '{print $1}' /var/log/httpd/access_log | sort | uniq -c | sort -nr | head
grep "10/Apr/2025" /var/log/httpd/access_log
一条典型访问日志:
192.168.1.1 - - [10/Apr/2025:12:00:01 +0800] "GET /index.html HTTP/1.1" 200 2326
含义:
192.168.1.1:客户端 IP-:远程用户10/Apr/2025:12:00:01:时间GET /index.html HTTP/1.1:请求200:状态码2326:返回字节数CentOS 使用 logrotate 自动切割日志:
ls /var/log/httpd/
你可能会看到:
access_log
access_log-20250410
如果你愿意,可以告诉我:
我可以给你更针对性的命令。