在 CentOS 上,Apache(通常是 httpd)的日志位置和配置方式如下:
在 CentOS 中,Apache 一般通过 httpd 安装:
yum install httpd
/var/log/httpd/
常见日志文件:
/var/log/httpd/access_log/var/log/httpd/error_log查看日志示例:
tail -f /var/log/httpd/access_log
tail -f /var/log/httpd/error_log
配置文件位置:
/etc/httpd/conf/httpd.conf
虚拟主机配置一般在:
/etc/httpd/conf.d/*.conf
CustomLog "logs/access_log" combined
常见日志格式:
commoncombined(包含 Referer 和 User-Agent)ErrorLog "logs/error_log"
LogLevel warn
LogLevel 可选:
debuginfonoticewarn(默认)errorcrit示例:
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html/example
ErrorLog /var/log/httpd/example_error.log
CustomLog /var/log/httpd/example_access.log combined
</VirtualHost>
修改后重启 Apache:
systemctl restart httpd
CentOS 默认使用 logrotate 管理 Apache 日志:
配置文件:
/etc/logrotate.d/httpd
示例内容:
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
delaycompress
postrotate
/bin/systemctl reload httpd.service > /dev/null 2>&1 || true
endscript
}
手动执行:
logrotate -f /etc/logrotate.d/httpd
# 实时查看访问日志
tail -f /var/log/httpd/access_log
# 查看错误
grep -i error /var/log/httpd/error_log
# 查看某个 IP 的访问
grep "192.168.1.100" /var/log/httpd/access_log
# 查看 404 请求
grep " 404 " /var/log/httpd/access_log
如果你是指:
可以告诉我你的具体需求,我可以进一步说明。