为什么我不能让 Apache 的 CustomLog 指令工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/525057/
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
Why can't I get Apache's CustomLog directive to work?
提问by Mike Spross
I'm trying to use Apache's CustomLogdirective to create some custom log files, but can't get it working. Here is the configuration I'm using for the custom logs:
我正在尝试使用 Apache 的CustomLog指令来创建一些自定义日志文件,但无法使其正常工作。这是我用于自定义日志的配置:
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
CustomLog /var/log/apache2/jb_common common
CustomLog /var/log/apache2/jb_referer referer
Apache creates both of these custom log files on startup, so it definitely sees the CustomLogdirectives, but it never writes anything to these files; however, the default access log (access.log) is being written to.
Apache 在启动时创建这两个自定义日志文件,因此它肯定会看到这些CustomLog指令,但它从不向这些文件写入任何内容;但是,access.log正在写入默认访问日志 ( )。
Any ideas? I'm running Apache 2.2 on Ubuntu 8.10.
有任何想法吗?我在 Ubuntu 8.10 上运行 Apache 2.2。
回答by Mike Spross
I have the same problem with Ubuntu 9.10 Server and Apache 2.2.12. I'm setting up a Subversion server with mod_dav_svnand added a CustomLogdirective to /etc/apache2/mods-available/dav_svn.confto log Subversion requests, but had the same problem (the log file was created when Apache started, but was never written to):
我在 Ubuntu 9.10 Server 和 Apache 2.2.12 上有同样的问题。我正在设置一个 Subversion 服务器,mod_dav_svn并添加了一个CustomLog指令来/etc/apache2/mods-available/dav_svn.conf记录 Subversion 请求,但遇到了同样的问题(日志文件是在 Apache 启动时创建的,但从未写入):
<Location /svn>
...
</Location>
LogFormat "%t %u %{SVN-ACTION}e" svn_log
CustomLog /var/log/apache2/svn_access.log svn_log env=SVN-ACTION
There are two workarounds for the issue that I found, which basically amount to the same thing. I'm documenting both here because they have different pros and cons.
我发现的问题有两种解决方法,它们基本上是相同的。我在这里记录两者,因为它们有不同的优点和缺点。
Workaround 1
解决方法 1
Delete the
CustomLogdirective from your configuration file, if you have it set up in a separate configuration file.Add the
CustomLogdirective to your site'sVirtualHostentry. For me this was in/etc/apache2/sites-available/default-sslbecause I'm only allowing SSL access to the Subversion repository. If you are using/etc/apache2/sites-available/default, you will want to edit that file instead (or in addition todefault-sslif you are using both).Restart Apache:
CustomLog如果您在单独的配置文件中设置了该指令,请从您的配置文件中删除该指令。将该
CustomLog指令添加到您站点的VirtualHost条目中。对我来说这是/etc/apache2/sites-available/default-ssl因为我只允许 SSL 访问 Subversion 存储库。如果您正在使用/etc/apache2/sites-available/default,您将需要编辑该文件(或者default-ssl如果您同时使用两者)。重启阿帕奇:
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/apache2 restart
Pro
亲
You can have multiple CustomLogdirectives in the VirtualHostentry for your site, and they will all work.
您可以CustomLog在VirtualHost站点的条目中包含多个指令,它们都将起作用。
Con
骗局
You have to move your CustomLogentry into your site's VirtualHostentry instead of having it in a separate configuration file.
您必须将CustomLog条目移动到站点的VirtualHost条目中,而不是将其放在单独的配置文件中。
Workaround 2
解决方法 2
Comment out the
CustomLogdirective(s) in your site'sVirtualHostentry. If you're using one of the default site configurations (defaultordefault-ssl), there will be aCustomLogdirective for the access log that you will need to comment out (yes, this turns off Apache's default access logging).Add your
CustomLogdirective to the appropriate configuration file. For me this was/etc/apache2/mods-available/dav_svn.conf.Restart Apache:
注释掉
CustomLog站点VirtualHost条目中的指令。如果您使用的是默认站点配置(default或default-ssl)之一,那么CustomLog您需要注释掉访问日志的指令(是的,这会关闭 Apache 的默认访问日志记录)。将您的
CustomLog指令添加到相应的配置文件中。对我来说这是/etc/apache2/mods-available/dav_svn.conf.重启阿帕奇:
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/apache2 restart
Pro
亲
You can keep your CustomLogdirective in a separate configuration file.
您可以将CustomLog指令保存在单独的配置文件中。
Con
骗局
This workaround has the obvious disadvantage that you have to disable Apache's default access logging, but for me I don't care that much since I'm only using the server for Subversion access.
这种解决方法有一个明显的缺点,即您必须禁用 Apache 的默认访问日志记录,但对我来说我并不在意,因为我只使用服务器进行 Subversion 访问。
Conclusion
结论
Neither of these workarounds are really ideal, but so far I haven't found a way to get it to work other than than the two workarounds above. I suppose we'll have to wait for the next release of Apache for this issue to be fixed.
这两种解决方法都不是很理想,但到目前为止,除了上述两种解决方法之外,我还没有找到其他方法让它工作。我想我们将不得不等待 Apache 的下一个版本才能修复这个问题。
回答by Germain
One problem you might be running into, is if you redirect http request to https via a rewrite rule, you might have two different configuration files for the same VirtualHost, one serving *:80 and another serving *:443
您可能会遇到的一个问题是,如果您通过重写规则将 http 请求重定向到 https,则同一个 VirtualHost 可能有两个不同的配置文件,一个服务 *:80,另一个服务 *:443
So maybe check that you didn't write your CustomLog directive only in the VirtualHost config file serving http!
因此,也许检查一下您是否仅在服务 http! 的 VirtualHost 配置文件中编写了 CustomLog 指令!
(yes, it did happen to me)
(是的,它确实发生在我身上)

