简体   繁体   English

禁用apache2日志

[英]Disable apache2 log

I only have 32GB on my server, and the logs is eating up that space quickly. 我的服务器上只有32GB,日志很快就耗尽了该空间。 So I want to disable the logs. 所以我想禁用日志。

I think I found where to do it, but since I'm a complete noob when it comes to server, I don't want to start changing things without being sure that they won't crash the server. 我想我已经找到了解决方法,但是由于我是服务器方面的菜鸟,所以我不想在不确保服务器不会崩溃的情况下开始进行更改。

In etc/apache2/apache2.conf, I found this: 在etc / apache2 / apache2.conf中,我发现了这一点:

    #
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

and in etc/apache2/conf.d/other-vhost-access-log, I found this: 在etc / apache2 / conf.d / other-vhost-access-log中,我发现了这一点:

# Define an access log for VirtualHosts that don't define their own logfile
CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined

What do I need to do to disable the logs? 我需要怎么做才能禁用日志?

Thanks in advance 提前致谢

If you truly want to disable the logs, you must comment out any ErrorLog and CustomLog directives in your Apache configuration files. 如果您确实想禁用日志,则必须注释掉Apache配置文件中的所有ErrorLogCustomLog指令。 On Debian, these will be located in /etc/apache2/httpd.conf and /etc/apache2/apache2.conf (the base configuration) and then /etc/apache2/sites-available/* (specific virtual host configurations). 在Debian上,它们将位于/etc/apache2/httpd.conf/etc/apache2/apache2.conf (基本配置)中,然后位于/etc/apache2/sites-available/* (特定的虚拟主机配置)中。

You can comment them out by adding a '#' character in front of them. 您可以通过在它们前面添加“#”字符来注释掉它们。

Once the changes are made, run /etc/init.d/apache2 restart for the changes to take effect. 进行更改后,请运行/etc/init.d/apache2 restart以使更改生效。

IMO, a better solution -- since logs are often very handy -- is to install log rotate as Sergey suggested above. IMO是一种更好的解决方案-由于日志通常非常方便-就是按照Sergey的建议安装日志轮转。 In Debian, run this: 在Debian中,运行以下命令:

 sudo apt-get install logrotate

logrotate will, in its default configuration, split logs daily and compress the old ones, saving a ton of disk space while preserving the logs themselves. 在默认配置下,logrotate将每天拆分日志并压缩旧日志,从而在保留日志本身的同时节省了大量磁盘空间。

The accepted answer here is wrong. 这里接受的答案是错误的。 Commenting out that line does not disable the errorlog, it just reverts it to the apache2 default. 注释掉该行不会禁用错误日志,而只是将其恢复为apache2默认值。 From the apache2 ErrorLog documentation : 从apache2 ErrorLog文档中

Default: ErrorLog logs/error_log (Unix) ErrorLog logs/error.log (Windows and OS/2) 默认值:ErrorLog日志/ error_log(Unix)ErrorLog日志/error.log(Windows和OS / 2)

In other words, this will be somewhere in the apache installation root 'logs' directory. 换句话说,这将在apache安装根目录“ logs”目录中的某个位置。

To disable I think you'll need to recompile without logging support (not sure if even possible), or pipe ErrorLog to /dev/null: 要禁用此功能,我认为您将需要在没有日志支持的情况下进行重新编译(甚至可能也不确定),或者将ErrorLog传递给/ dev / null:

ErrorLog "|/dev/null" ErrorLog“ | / dev / null”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM