Nginx

LogZilla App Store application: Nginx

Linux nginx

Rule Function

NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. This rule adds user tags for a few user tags (see below).

Vendor Documentation

Incoming Log Format

The default Nginx log format is space-separated values. In order to use the current rule with Nginx the log format must be customized, as detailed in the Configuration section below.

When configured properly, the log format is space-separated key-value pairs. See the bottom for examples.

Configuration

Nginx must be configured both with the correct log format as well as the correct log destination. Verify that include /etc/nginx/conf.d/*.conf; is in the http { section of /etc/nginx/nginx.conf, and add it if it is not already there.

Then the following should be put in file /etc/nginx/conf.d/logging.conf.

# LogZilla Custom Log Format
# Requires Nginx >= v1.7.1

log_format logzilla 'Site="$server_name" Server="$host" DstPort="$server_port" '
               'DstIP="$server_addr" Src="$remote_addr" SrcIP="$realip_remote_addr" '
               'User="$remote_user" Time_Local="$time_local" Protocol="$server_protocol" '
               'Status="$status" Bytes_Out="$bytes_sent" '
               'Bytes_In="$upstream_bytes_received" HTTP_Referer="$http_referer" '
               'User_Agent="$http_user_agent" Nginx_Version="$nginx_version" '
               'HTTP_X_Forwarded_For="$http_x_forwarded_for" '
               'HTTP_X_Header="$http_x_header" URI_Query="$query_string" URI="$uri" '
               'HTTP_Method="$request_method" Response_Time="$upstream_response_time" '
               'Cookie="$http_cookie" Request_Time="$request_time" ';

  # Send logs to LogZilla Server
  access_log syslog:server=logzilla.abcd.com:514,tag=nginx_access logzilla;
  error_log syslog:server=logzilla.abcd.com:514,tag=nginx_error notice;

After this configuration change has been made Nginx must be restarted using service nginx restart and verify reception of logs.

User Tags

User tag names (for those fields applicable) are the same as the field names defined in the configuration above. Note that underscores (_) in the field names are converted to spaces ( ) in the user tag name.

TaggedField NameExampleDescription
SiteSitelogs.logzilla
ServerServerlogs.logzilla
DstPort443the destination port for the request
DstIP18.68.11.35
Src16.56.15.199the source of the request (appears to be same as src_ip)
SrcIP16.56.15.199the source ip of the request
Userjohndthe username (if available) making the request
Time_Local03/Jan/2018:14:07:58 -0500the date & time of the request
ProtocolHTTP/1.1the transport protocol being used for the request
Status200the http status code returned from the request
Bytes_Out3995the number of bytes sent for the request
Bytes_In-the number of bytes received for the request
HTTP_Referer-the URI that referred the user here
User_AgentMozilla/5.0the user agent being used for the request
Nginx_Version1.12.2nginx version number
HTTP_X_Forwarded_For-the IP address of the originating ip
HTTP_X_Header-unknown
URI_Query-unknown
URI/index.htmlURI of the request
HTTP_MethodGETHTTP operation being performed
Response_Time-time taken for the response to be sent
Cookie-any cookies provided by the client to this page
Request_Time0.000time taken for request to be received

HC Tags

HC_TAGS={
     "SrcIP",
     "DstIP",
     "URI",
 }

Log Examples

Typical page GET request (200)

Site="localhost" Server="192.168.250.112” DstPort="80" DstIP="192.168.250.112" 
Src="192.168.250.2" SrcIP="192.168.250.2" User="-" 
Time_Local="17/Nov/2021:17:45:07 +0000" Protocol="HTTP/1.1" Status="304" 
Bytes_Out="189" Bytes_In="-" HTTP_Referer="-" User_Agent="Mozilla/5.0 (X11; 
Ubuntu; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0" Nginx_Version="1.18.0" 
HTTP_X_Forwarded_For="-" HTTP_X_Header="-" URI_Query="-" URI="/main.html" 
HTTP_Method="GET" Response_Time="-" Cookie="-" Request_Time="0.000" 

Page POST request (200)

Site="localhost" Server="192.168.250.112” DstPprt="80" DstIP="192.168.250.112" 
Src="192.168.250.2" SrcIP="192.168.250.2" User="-" 
Time_Local="17/Nov/2021:17:46:13 +0000" Protocol="HTTP/1.1" Status="200" 
Bytes_Out="331" Bytes_In="-" HTTP_Referer="http://192.168.250.112/poster.html" 
User_Agent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:94.0) Gecko/20100101 
Firefox/94.0" Nginx_Version="1.18.0" HTTP_X_Forwarded_For="-" HTTP_X_Header="-" 
URI_Query="" URI="/posted.html" HTTP_Method="GET" Response_Time="-" Cookie="-" 
Request_Time="0.000" 

Page not found (404)

Site="localhost" Server="192.168.250.112” DstPort="80" DstIP="192.168.250.112" 
Src="192.168.250.2" SrcIP="192.168.250.2" User="-" 
Time_Local="17/Nov/2021:17:46:21 +0000" Protocol="HTTP/1.1" Status="404" 
Bytes_Out="326" Bytes_In="-" HTTP_Referer="-" User_Agent="Mozilla/5.0 (X11; 
Ubuntu; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0" Nginx_Version="1.18.0" 
HTTP_X_Forwarded_For="-" HTTP_X_Header="-" URI_Query="-" URI="/nothere.html" 
HTTP_Method="GET" Response_Time="-" Cookie="-" Request_Time="0.000" 
Nginx | LogZilla Documentation