log-var-set: Set variables before access log writing
Debian/Ubuntu installation
These docs apply to the APT package nginx-module-log-var-set provided by the GetPageSpeed Extras repository.
- Configure the APT repository as described in APT repository setup.
- Install the module:
sudo apt-get update
sudo apt-get install nginx-module-log-var-set
Show suites and architectures
| Distro | Suite | Component | Architectures |
|----------|-------------------|-------------|-----------------|
| debian | bookworm | main | amd64, arm64 |
| debian | bookworm-mainline | main | amd64, arm64 |
| debian | trixie | main | amd64, arm64 |
| debian | trixie-mainline | main | amd64, arm64 |
| ubuntu | focal | main | amd64, arm64 |
| ubuntu | focal-mainline | main | amd64, arm64 |
| ubuntu | jammy | main | amd64, arm64 |
| ubuntu | jammy-mainline | main | amd64, arm64 |
| ubuntu | noble | main | amd64, arm64 |
| ubuntu | noble-mainline | main | amd64, arm64 |
ngx_http_log_var_set_module allows setting the variable to the given value before access log writing.
Table of Content
Status
This Nginx module is currently considered experimental. Issues and PRs are welcome if you encounter any problems.
Synopsis
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$log_field1" "$log_field2"';
access_log /spool/logs/nginx-access.log;
server {
listen 127.0.0.1:80;
server_name localhost;
location / {
log_var_set $log_field1 $upstream_http_custom_header1;
log_var_set $log_field2 $upstream_http_custom_header2;
proxy_pass http://example.upstream.com;
}
}
Directives
log_var_set
Syntax: log_var_set $variable value [if=condition];
Default: -
Context: http, server, location
Sets the request variable to the given value before access log writing. The value may contain variables from request or response, such as $upstream_http_*. These directives are inherited from the previous configuration level only when there is no directive for the same variable defined at the current level.