Task:
Depending on where the request came to apache (on which hostname), write logs to a file that will contain the host or ServerName header or% {HTTP_HOST} in the log name. In this example, I mean that% {HTTP_HOST} is used

<VirtualHost 192.168.10.10:8888> UseCanonicalName Off ServerName test.example.ru ServerAlias test1.example.ru test2.example.ru VirtualDocumentRoot /home/%1/html CustomLog "/home/logs/%{HTTP_HOST}-access.log" combined 

In this case:

If the request came to test1.example.ru, the log should be written to: /home/logs/test1.example.ru-access.log .

If the request came to test2.example.ru then respectively in:
/home/logs/test2.example.ru-access.log .

What methods can be implemented?

In particular, it is still interesting to specify the same logic for php logs

  <IfModule mod_php5.c> php_value error_log "/home/logs/php/%{HTTP_HOST}-www-error_php.log" php_admin_value log_errors 1 </IfModule> 

Debian 7
Apache2 2.2.22-13

  • The option to divide VirtualHost into the number of ServerName and in each register your file - does not suit you? - MANKK
  • @ MAN69K No, this is an excessive number of entries in the config, there may be more than 15 domains, and ServerAlias *.example.ru may have a wildcard. In this example, I specifically indicated only three domains. - Kislik

0