在 Ubuntu 上使用 Apache(通常是 apache2)时,日志(Logs)主要用来记录服务器的运行情况和客户端的访问行为。它们对排查问题、安全审计、性能优化和了解用户行为非常关键。
下面是 Apache 在 Ubuntu 中常见日志及其作用:
默认路径一般在:
/var/log/apache2/
常见文件:
access.log —— 访问日志error.log —— 错误日志other_vhosts_access.log —— 其他虚拟主机访问日志(启用多站点时)记录每一次 HTTP 请求
作用:
示例内容:
192.168.1.10 - - [12/Jan/2026:10:22:01 +0800] "GET /index.html HTTP/1.1" 200 2326
包含信息:
记录 Apache 运行错误和警告
作用:
常见错误示例:
[error] [client 1.2.3.4] File does not exist: /var/www/html/favicon.ico
[alert] Could not open configuration file
如果你配置了多个网站:
CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
作用:
看 error.log
看 access.log
在 Ubuntu Apache 中可设置:
LogLevel warn
常见级别:
debug(最详细)infonoticewarn(默认)errorcritUbuntu 默认用 logrotate 自动切割日志:
/etc/logrotate.d/apache2
建议:
Apache 日志就是服务器的“黑匣子”,出了问题先查日志,90% 的问题都能定位。
如果你愿意,我可以:
直接把日志贴出来或说你的使用场景就行。