在 Ubuntu 上关闭 Apache 日志,通常有几种程度不同的做法,从“完全关闭”到“只减少日志”。下面按常见需求说明。
通常配置文件在:
/etc/apache2/apache2.conf
/etc/apache2/sites-enabled/000-default.conf
找到类似以下内容:
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
改为:
# ErrorLog ${APACHE_LOG_DIR}/error.log
# CustomLog ${APACHE_LOG_DIR}/access.log combined
或者直接指向 /dev/null(更安全,避免 Apache 启动报错):
ErrorLog /dev/null
CustomLog /dev/null combined
CustomLog /dev/null combined
或注释掉:
# CustomLog ${APACHE_LOG_DIR}/access.log combined
如果你用的是虚拟主机(如 /etc/apache2/sites-enabled/xxx.conf):
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
# 关闭日志
ErrorLog /dev/null
CustomLog /dev/null combined
</VirtualHost>
如果你只是不想看某些调试日志,例如:
# RewriteLog /var/log/apache2/rewrite.log
# RewriteLogLevel 0
sudo systemctl restart apache2
或:
sudo service apache2 restart
/dev/null如果你能说明:
我可以给你更合适的配置示例。