sqlitelog

The sqlitelog directive configures NGINX to log requests to an SQLite database.

Syntaxsqlitelog path format [buffer=buffer_size] [max=max_entries] [if=condition];
Defaultnone
Contexthttp, server
Arguments1+

Description

The sqlitelog directive enables logging of HTTP request details into an SQLite database, allowing for efficient storage and querying of access logs. This directive accepts one or more arguments, including the path to the SQLite database file and the log format previously defined by the sqlitelog_format directive. Furthermore, it provides options for configuring the logging buffer size and other parameters that affect data handling and database interactions.

When used within the http or server contexts, the sqlitelog directive works by writing the formatted logging entries to the specified SQLite database. The database schema is defined according to the format provided, capturing essential request data such as the remote address, request time, and status codes. As requests are processed, these data points are logged asynchronously if the sqlitelog_async directive is activated, helping to mitigate performance impacts on the NGINX worker process.

The directive also supports conditional logging through an optional filter. Users can define criteria for when logs should be recorded, thus allowing for more granular control over what data is saved. This is particularly useful in scenarios where only specific types of traffic need to be monitored, enabling efficient log cleaning and maintenance efforts.

Config Example

http {
    sqlitelog_format myformat $remote_addr $time_local $host $request_uri $request_time $status;
    sqlitelog /tmp/access.db myformat buffer=128K max=5;
}

Ensure the SQLite database file has appropriate write permissions for the NGINX user, or logging will fail.

Overly large log buffers can delay log writes, potentially leading to data loss in high traffic situations if the server crashes.

If using the async mode, be aware of potential complexity in troubleshooting as logs may not be written at the point of request processing.

← Back to all directives