I'm trying to make a wildcard VirtualHost conf file for apache2, and I'm not sure how to handle the ErrorLog
and CustomLog
settings to put the logs where I want them to go. As you can see in the second VirtualHost
, I have the logs in a logs
folder in the domains DocumentRoot
. This works fine for static VirtualHost
s, but how would I go about it for a wildcard VirtualHost
. eg, the first VirtualHost
.
NameVirtualHost *:80
# Wild card all subdomains
<VirtualHost *:80>
ServerAlias *.example.com
VirtualDocumentRoot /var/www/%0/public
ErrorLog ?????
CustomLog ????? combined
</VirtualHost>
# Main domain
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined
</VirtualHost>
I have tried going ErrorLog /var/www/*.example.com/logs/error.log
and ErrorLog /var/www/%0/logs/error.log
and the same for CustomLog
, but when I try to restart apache it throws an error.
What syntax should I use to get a working version of my ErrorLog
example above?
I have seen Wildcards in Virtual Hosts with dynamic logs? , but it is not really what I am after as it still ends up putting all the logs into one big file rather than having them split into their own subdomain specific folders.
VirtualHost
segment, but I thought I would try to automate the process of creating new subdomains whenever I needed a new site. This way I could just create the folder in the correct position and I have a live site without having to edit any config files. Having the logs separate is just much more tidy than having them all in one file, and follows the log format of what I had originally.