Linux Apache访问日志自动设置权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9568118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:00:00  来源:igfitidea点击:

Apache access log automatically set permissions

linuxpermissionsapache2logging

提问by Parth

For some tests I'm doing, I'm required to remotely tail the apache access log via ssh. I can successfully do that only when the permissions are accurately set for the log. I've noticed that once a week, a new apache access.log is created and the permissions are reset.

对于我正在做的一些测试,我需要通过 ssh 远程跟踪 apache 访问日志。只有在为日志准确设置权限时,我才能成功做到这一点。我注意到每周都会创建一个新的 apache access.log 并重置权限。

My current work around is editing the permissions on the log once a week:

我目前的工作是每周编辑一次日志权限:

chmod 644 /var/log/apache2/access.log

I was wondering if there was a more permanent solution such as extending the time that the old log remains or automatically setting permissions when the new log is created.

我想知道是否有更持久的解决方案,例如延长旧日志的保留时间或在创建新日志时自动设置权限。

If it matters, I'm running the server on Ubuntu 11.10

如果重要的话,我在 Ubuntu 11.10 上运行服务器

采纳答案by Kirby Todd

Edit your logrotate.conf file to set the correct owner/permissions for the apache.log file. Something like this:

编辑您的 logrotate.conf 文件,为 apache.log 文件设置正确的所有者/权限。像这样的东西:

/var/log/apache2/access.log {
    weekly
    create 0644 root utmp
    rotate 1
}

(Edit: Changed mode from 0744 to 0644. No need to set the execute bit.)

(编辑:将模式从 0744 更改为 0644。无需设置执行位。)

回答by Wesley

Maybe another application, like logrotate, is altering the logs? (Sounds like it, as it only happens weekly) I don't think Apache itself is responsible for the permissions chance.

也许另一个应用程序,如 logrotate,正在改变日志?(听起来像,因为它只每周发生一次)我不认为 Apache 本身对权限机会负责。

A good place to start is check /etc/cron./* to see if any cron jobs are touching the access.log

检查/etc/cron.conf是一个不错的起点/* 查看是否有任何 cron 作业正在访问 access.log

Good luck!

祝你好运!