同一 VirtualHost 下 Apache 中的多个日志文件(每个 WSGI 项目)

发布于 2024-10-12 11:22:10 字数 721 浏览 3 评论 0原文

我当前正在运行一个设置,其中根据 URL 提供不同的项目:

http://machine_address/project_nameA
http://machine_address/project_nameB
(...)

由于所有项目都在同一个 VirtualHost 下提供服务,因此我最终让每个项目由不同的 WSGIDaemonProcess 处理> 以便它们可以独立重新启动。此外,每个Daemon根据项目设置在不同的用户下运行。

此设置的唯一限制是所有 Apache 日志仍然进入 /var/log/apache2/ 上的同一文件。

我想要的是每个项目都编写自己的日志,允许给定项目的所有者监视项目特定的日志(访问、错误......)。

我尝试使用 ErrorLogTransferLog 指令,但由于这些指令仅限于 ServerVirtualHost level,我无法找到一种方法来划分日志。

所以这个问题分为两个:

  • 如何在每个项目的基础上拥有单独的日志?
  • 有什么方法可以使用特定的组/所有者和权限创建这些日志,以便项目所有者可以读取但不能写入日志?

I'm currently running a setup where different projects are served according to URL:

http://machine_address/project_nameA
http://machine_address/project_nameB
(...)

Since all projects are served under the same VirtualHost, I ended up having each project handled by a different WSGIDaemonProcess such that they can be restarted independently. In addition, each Daemon is run under a different user according to the project settings.

The only limitation I have with this setup is that all the Apache logs still go into the same file on /var/log/apache2/.

What I would like to have is each project writing its own log, allowing owners of a given project to monitor the project specific logs (access, error,...).

I've tried to use the ErrorLog and TransferLog directives, but since these are restricted to either the Server or the VirtualHost level, I couldn't figure out a way to compartmentalize the logs.

So this question is divided into two:

  • How can I have individual logs on a per-project basis?
  • Is there any way to have these logs being created with a specific group/owner and permission, such that project owners can read but not write to the logs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝情姑娘 2024-10-19 11:22:10

没有办法通过 mod_wsgi 的配置来表明来自 mod_wsgi 守护进程的所有 stdout/stderr 都应该转到与 VirtualHost 设置不同的备用日志文件。

已经考虑过,但某些错误消息实际上是从 Apache 子进程生成的,并且这些错误消息无法重定向到该日志文件。将消息发送到两个不同的日志所带来的混乱似乎不值得。

如果您仍然想尝试,那么您需要做的第一件事就是在 WSGI 脚本文件中执行以下操作:

import sys
sys.stderr = sys.stdout = file('/tmp/daemon.log', 'a')

There is no way through configuration of mod_wsgi to say that all stdout/stderr from a mod_wsgi daemon process should go to an alternate log file than that setup for the VirtualHost.

It has been considered, but certain error messages are actually generated from Apache child processes and those couldn't be redirected to that log file. The confusion from having messages go to two different logs didn't seem worth it.

If you still want to try, then all you need do is as very first thing in WSGI script file do something like:

import sys
sys.stderr = sys.stdout = file('/tmp/daemon.log', 'a')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文