完全禁用 Apache 日誌記錄

完全禁用 Apache 日誌記錄

我有一台在線運行的舊伺服器,上面有超過 250 個站點,我不確定,但也許apachelog 中的日誌檔案太多會降低伺服器速度嗎?

現在,由於我不需要 Apache 日誌,該如何完全停用所有日誌記錄?

答案1

我禁用了所有虛擬主機日誌記錄:

find /etc/apache2/sites-enabled/* -exec sed -i 's/#*[Cc]ustom[Ll]og/#CustomLog/g' {} \;
find /etc/apache2/sites-enabled/* -exec sed -i 's/#*[Ee]rror[Ll]og/#ErrorLog/g' {} \;

並且註解掉了/etc/apache2/apache2.conf

#ErrorLog ${APACHE_LOG_DIR}/error.log

並且添加了

ErrorLog /dev/null

優雅地重新啟動 apache:

apache2ctl graceful

我在不同的地方有很多日誌,所以我可以用以下方式查看結果

 tail -n 1 -f /var/kunden/logs/*log /var/kunden/logs/*log /var/log/apache2/*log

如果您想將所有日誌記錄到一個文件中,您可以/etc/apache2/apache2.conf再次編輯並新增這些行:

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log  "%h %v %l %u %t \"%r\" %>s %b"

並註解掉

#ErrorLog /dev/null

答案2

對於所有擁有該 other_vhosts_access.log文件並希望停用它的人,請註解掉以下行:

#CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined

在:

/etc/apache2/conf-available/other-vhosts-access-log.conf

或停用此設定檔:

sudo a2disconf other-vhosts-access-log

相關內容