softmixx background

nginx Konfiguration

Webserver

Logfile Konfiguration in nginx

[ 19.02.2021 | Alex]
In der Standardkonfiguration schreibt nginx jeden Webserver Zugriff in ein access.log und error.log. Da ich aber nur bestimmte Zugriffe protokollieren will, wird die nginx Konfiguration ergänzt.

Dazu lege ich zunächst mit der map Direktive fest, welche Zugriffe beachtet werden sollen:

http {
 ...
 map $request_uri $logaccess{
     default                  0;
     /                        1;
     ~*\.(html|php|json|xml)$ 1;
 }
 ...

Mit diesem Eintrag habe ich nun eine Regel 'logaccess' definiert, die nur Webserver URLs mit den Endungen ".html,.php,.json,.xml" und 'root' (/) beachtet.

Im Konfigurationsabschnitt des Webservers aktiviert dann die folgende Zeile den Log Filter 'logaccess':

server {
 ...
        access_log /var/log/nginx/meine-domain.de/access.log dwt if=$logaccess;
 ...
}  

 Die Option 'dwt' verweist auf das zuvor festgelegte Logformat, z.B.:

log_format dwt '$time_local|$status|$remote_addr|$request|$http_referer';