/nginx_requestid

Nginx request_id module

Primary LanguageC

The ngx_http_requestid_module is designed to generate a unique request identificator.

The module sets $trequest_id variable with a unique request ID.

The $trequest_id variable is composed of (time){13} and (md5(ngx_pid, connection_number, rand())){19}, where:
  * time - timestamp in milliseconds
  * ngx_pid - nginx process id
  * connection_number - connection counter value local to worker process
  * rand() - random number

Supports both old and new configuration methods including dynamic compilation.

Example configurations:

# Set Proxy Header
location / {
     trequestid on;
     proxy_pass http://127.0.0.1;
     proxy_set_header X-Request-Id $trequest_id;
}


# Set HTTP Header
location / {
     add_header X-Request-Id $trequest_id;
}

# Write request id to log
log_format main '$remote_addr - $remote_user [$time_local]  '
		'"$request" $status $body_bytes_sent $trequest_id '
		'"$http_referer" "$http_user_agent"';


Configuration:

syntax: trequestid on | off
default: off
context: server, location