Wie passen Sie LogFormat für virtuelle Apache-Hosts an?

6349
Mina Hafzalla

Ich brauche dazu wirklich Hilfe. Mein Server verfügt über mehrere virtuelle Hosts, jeder virtuelle Host verfügt über ein Zugriffsprotokoll. Ich muss das LogFormat für jeden auf dem Server vorhandenen virtuellen Host anpassen können. Ich habe LogFormat geändert, betrifft httpd.confaber nur das Master-Zugriffsprotokoll und nicht die virtuellen Hosts.

Hier ist mein LogFormat:

<IfModule log_config_module> LogFormat "%v:%a %l %u %t \"%r\" %>s %b \"%i\" \"%i\" %i" combinedvhost LogFormat "%h %l %u %t \"%r\" %>s %b \"%i\" \"%i\" %i" combined LogFormat "%h %l %u %t \"%r\" %>s %b %i" common  CustomLog "logs/access_log" combined CustomLog logs/access_log combinedvhost  <IfModule logio_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%i\" \"%i\" %i" combinedio </IfModule>  </IfModule>  <IfModule mod_log_config.c> LogFormat "%v:%a %l %u %t \"%r\" %>s %b \"%i\" \"%i\" %i" combinedvhost LogFormat "%h %l %u %t \"%r\" %>s %b \"%i\" \"%i\" %i" combined LogFormat "%h %l %u %t \"%r\" %>s %b %i" common LogFormat "%i -> %U" referer LogFormat "%i" agent  CustomLog logs/access_log common CustomLog logs/access_log combined CustomLog logs/access_log combinedvhost  </IfModule> 

Das obige LogFormat betrifft nur das Master-Zugriffsprotokoll, das sich unter befindet: /usr/local/apache/logs/access_logDie virtuellen Hosts auf dem Server, auf denen sich die Zugriffsprotokolle befinden, sind jedoch nicht betroffen:/home/username/access-logs/domain.com

Ich bin mir nicht sicher, ob ich etwas falsch im LogFormat habe oder etwas fehlt. Ich habe viele Stunden damit verbracht, dieses Problem zu lösen, habe aber keine Lösung gefunden. Ich würde es sehr schätzen, wenn jemand etwas Licht ins Dunkel bringen könnte. Vielen Dank.

1

2 Antworten auf die Frage

2
boot13

Der Trick besteht darin, CustomLog-Anweisungen in jedem VirtualHost in Ihren Apache-Konfigurationsdateien hinzuzufügen. Zum Beispiel:

<VirtualHost *:80> ServerName www.site1.com DocumentRoot /var/www/www.site1.com/htdocs CustomLog /var/log/apache/www.site1.com-access.log combined ErrorLog /var/log/apache/www.site1.com-error.log </VirtualHost>  <VirtualHost *:80> ServerName www.site2.com DocumentRoot /var/www/www.site2.com/htdocs CustomLog /var/log/apache/www.site2.com-access.log combined ErrorLog /var/log/apache/www.site2.com-error.log </VirtualHost> 

Es gibt weitere nützliche Beispiele hier .

Können Sie das näher erläutern (wie es geht)? fixer1234 vor 9 Jahren 0
0
Puneet Khurana

Der Trick ist, dass Sie sowohl LogFormat als auch CustomLog in demselben VirtualHost-Pool haben sollten

 <VirtualHost *:443> ServerName my.site.com LogFormat "%i %l %u %t \"%r\" %>s %b %D " commonvhost ErrorLog "|/opt/mw/apache-2.4.25-instance1/bin/rotatelogs /apps/logs/my.site.com-443-error.%Y.%m.%d.log 86400" CustomLog "|/opt/mw/apache-2.4.25-instance1/bin/rotatelogs /apps/logs/my.site.com-443-access.%Y.%m.%d.log 86400" commonvhost </VirtualHost>  <VirtualHost *:80> ServerName my.site.com LogFormat "%i %l %u %t \"%r\" %>s %b %D " commonvhost ErrorLog "|/opt/mw/apache-2.4.25-instance1/bin/rotatelogs /apps/logs/my.site.com-80-error.%Y.%m.%d.log 86400" CustomLog "|/opt/mw/apache-2.4.25-instance1/bin/rotatelogs /apps/logs/my.site.com-80-access.%Y.%m.%d.log 86400" commonvhost </VirtualHost>