Apache服务器——多个目录,不同的错误日志 [英] Apache server -- multiple directories, different error logs

查看:26
本文介绍了Apache服务器——多个目录,不同的错误日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在/var/www 中有两个目录(比如/var/www/app1 和/var/www/app2),我想将它们的错误日志发送到不同的文件.两者都在同一个域下,所以我认为我不能把它们放在不同的虚拟主机下.因此,例如,我将访问它们:

I have two directories in /var/www (say, /var/www/app1 and /var/www/app2) whose error logs I want sent to different files. Both are under the same domain, so I think that I can't put them under different virtual hosts. So, for example, I would access them as:

http://localhost/app1

http://localhost/app2

我看到了这个页面:

为Apache中的不同子目录生成访问日志

其解决方案非常适合访问日志.但是,env"参数似乎不适用于 ErrorLog 指令.

whose solution works perfectly for the access logs. However, the "env" argument doesn't seem to work with the ErrorLog directive.

在这个发现"之前,我正在研究这个,这似乎是错误的:

Before this "discovery", I was working on this, which seems wrong:

<VirtualHost *:80>
  ServerAdmin ray@localhost

  DocumentRoot /var/www/app1

  <Directory />
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order deny,allow
    allow from all
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/app1/error.log

  LogLevel warn

  CustomLog ${APACHE_LOG_DIR}/app1/access.log combined
</VirtualHost>

我有点不知所措.也就是说,如果有某种方法可以让 ErrorLog 工作,或者我是否应该继续尝试为每个目录配置一个虚拟主机.任何帮助,将不胜感激!谢谢!

I'm somewhat lost about what I should be doing. That is, if there is some way to get ErrorLog to work or if I should keep trying with configuring a virtual host for each directory. Any help would be appreciated! Thank you!

推荐答案

为什么要在 VirtualHost 上下文中为 / 设置 Directory 选项?使用 而不是

Why do you set Directory options for / in the VirtualHost context? Use <Directory /var/www/app1> instead of <Directory />

由于 Apache ErrorLog 指令文档 其上下文是 server config, virtual host - 这意味着只能为整个服务器或 VirtalHost 定义 ErrorLog,而不能为 Directory.所以如果你想将不同的日志发送到不同的文件,尝试使用 SetEnvIf 来设置一个 Env 变量.根据您所在的目录,它应该类似于 SetEnvIf Request_URI ^\/a1\/a1SetEnvIf Request_URI ^\/a2\/!a1.然后根据 a1 环境变量写入日志.

Due to the Apache ErrorLog directive docs its context is server config, virtual host - which means that it's only possible to define ErrorLog for the whole server or for a VirtalHost, not for a Directory. So if you want to send different logs to different files, try to use SetEnvIf to set an Env variable. Depeding on the directory where you are, it should be something like SetEnvIf Request_URI ^\/a1\/ a1 and SetEnvIf Request_URI ^\/a2\/ !a1. Then write logs depending on the a1 environment variable.

这篇关于Apache服务器——多个目录,不同的错误日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆