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.

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

when a request to example.com is made.

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)?

Thanks

有帮助吗?

解决方案

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>

其他提示

You can do this with VirtualHosts by only maintaining 1 VirtualHost for several Domains using ServerAlias:

<VirtualHost *:80>
        ServerAdmin ...
        ServerName domain1.bla.com
        ServerAlias service.bla.com domain5.domain.xxx
        DocumentRoot /www/vhosts/xxx/public

        ErrorLog /www/vhosts/xxx/log/error.log
        CustomLog /www/vhosts/ccc/log/access.log combined
        LogLevel warn

        <Directory "/www/vhosts/ccc/public">
                Options FollowSymLinks MultiViews
                php_admin_flag safe_mode On
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top