在 CentOS 上,Apache 通常叫 httpd(不是 apache2,apache2 是 Debian/Ubuntu 的叫法)。下面给你常用的日志相关操作和说明。
默认日志目录:
/var/log/httpd/
常见日志文件:
/var/log/httpd/access_log/var/log/httpd/error_logtail -f /var/log/httpd/access_log
tail -f /var/log/httpd/error_log
tail -n 100 /var/log/httpd/error_log
配置文件位置:
/etc/httpd/conf/httpd.conf
或虚拟主机配置:
/etc/httpd/conf.d/*.conf
相关配置项示例:
ErrorLog "logs/error_log"
CustomLog "logs/access_log" combined
combined 是常用日志格式,包含:
CentOS 使用 logrotate:
配置文件:
/etc/logrotate.d/httpd
手动执行轮转测试:
logrotate -d /etc/logrotate.d/httpd
强制轮转:
logrotate -f /etc/logrotate.d/httpd
tail -f /var/log/httpd/error_log
看 access_log 中的状态码。
常见错误:
Permission denied: [client x.x.x.x] AH00035
一般是目录权限或 SELinux 问题。
如果你是指 CentOS 上用 apache2(自己编译或非标准安装),或者你想 按虚拟主机分离日志 / 自定义日志格式 / 分析日志,可以告诉我具体需求。