在 CentOS 系統下,Apache 的日志文件通常位于 /var/log/httpd/
目錄中。要查看 Apache 日志,你可以使用 tail
、less
、grep
等命令。以下是一些常用的命令示例:
sudo tail -f /var/log/httpd/access_log
這個命令會實時顯示訪問日志的內容。-f
選項表示 “follow”,即持續跟蹤日志文件的更新。
sudo tail -f /var/log/httpd/error_log
同樣,這個命令會實時顯示錯誤日志的內容。
grep
搜索特定關鍵詞:例如,要查找訪問日志中包含 “example.com” 的行,可以使用以下命令:
sudo grep "example.com" /var/log/httpd/access_log
要查找錯誤日志中包含 “404” 的行,可以使用以下命令:
sudo grep "404" /var/log/httpd/error_log
less
分頁查看日志:sudo less /var/log/httpd/access_log
在 less
命令中,你可以使用上下箭頭鍵或 PgUp/PgDn 鍵來翻頁,按 “q” 鍵退出。
注意:根據你的 CentOS 版本和 Apache 配置,日志文件的位置可能有所不同。如果上述路徑不適用,請檢查 Apache 配置文件(通常位于 /etc/httpd/conf/httpd.conf
或 /etc/apache2/apache2.conf
),找到 ErrorLog
和 CustomLog
指令,它們指定了日志文件的位置。