基于主机名的动态Apache日志目录 [英] Dynamic apache log directory based on hostname
问题描述
我有一个供多个域使用的PHP应用程序.为了避免维护多个虚拟主机,我只设置了一个默认" Apache虚拟主机,以将对服务器的任何传入请求定向到应用程序目录.
I have a PHP application which is used by multiple domains. To avoid maintaining multiple vhosts, I have just setup a single "default" Apache vhost to direct any incoming request to the server to the application directory.
我要做的是根据命中服务器的主机名动态设置Apache访问和错误日志路径.
What I want to do is to set the Apache access and error log paths dynamically based on the hostname hitting the server.
例如,我想将日志路径设置为:
For example, I would like to set the log paths to be something like:
/var/log/application_name/example.com/error.log
/var/log/application_name/example.com/access.log
向example.com
发出请求时.
有可行的方法吗?我已经看过使用任何Apache环境变量,但是由于这些都是在捕获请求时设置的,因此我认为这些变量无法在ErrorLog或CustomLog指令中使用.我只是需要在应用程序级别(即在PHP中)手动设置日志目录吗?
Is there a viable way to do this? I've looked at using any of the Apache environment variables, but as these are setup as the request is captured, I don't think these would be available for use in the ErrorLog or CustomLog directives. Is it that I just need to set the log directory manually at the application level (i.e in PHP)?
谢谢
推荐答案
我使用这样的设置,其中我的logsplit.sh脚本根据%U写入日志文件:
I use a setup like this where my logsplit.sh script writes to log files based on the %U:
<VirtualHost *:80>
ServerName myserver.com
ServerAlias *.myserver.com
VirtualDocumentRoot /home/%1/www/
LogFormat "%U %h %l %u %t \"%r\" %>s %b" common
CustomLog "|/usr/local/logsplit.sh" common
</VirtualHost>
这篇关于基于主机名的动态Apache日志目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!