大网数据广告活动
服务器运维问答

Tell Apache to create error.log/access.log as different user

· 52CE 我爱测

If you tell Apache to use CustomLog files, Apache2 will create these files on startup. And it always gives them to user root:root. How can I change this behavior? Background Apache runs with SuexecUserGroup www-data www-data and …

问题原文

原帖链接 · BurninLeo · CC BY-SA 3.0

If you tell Apache to use CustomLog files, Apache2 will create these files on startup. And it always gives them to user root:root. How can I change this behavior?

Background

Apache runs with

SuexecUserGroup www-data www-data

and at the same time, I use a CustomLog that pipes it output to a script. The script removes two bytes from the IP and then wirtes to the logfile. As you cannot tell Apache to omit the IP from the error.log, this piped-output is important (regarding German privacy law).

The script cannot access my custom log if this does not belong to www-data.

If I change the owner, everthing works fine.

I also know how to change the file owner when logrotate renames and re-creates the logfile.

However, if I stop the Apache process, delete the logfiles, and then restart the Apache process, new files beloging to root:root are created.

How can I tell Apache to create the new, void files as/for www-data on startup?

已采纳解答

原帖链接 · Alien Life Form · CC BY-SA 3.0

This sentence:

The script cannot access my custom log if this does not belong to www-data.

Is in direct contradiction with http://httpd.apache.org/docs/current/logs.html#piped:

Piped log processes are spawned by the parent Apache httpd process, and inherit the userid of that process. This means that piped log programs usually run as root. It is therefore very important to keep the programs simple and secure.

If the scenario you describe is somehow correct, you can still sidestep the issue by

  1. Ignoring the logfile name given in the config file
  2. Devising your own logfile name within the script
  3. Redirecting stdout to the file of your choosing as in (2)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-06-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。