$nginx_version

The variable $nginx_version holds the version number of the currently running NGINX instance. — NGINX Core (HTTP)

$nginx_version NGINX Core (HTTP)

Description

The variable $nginx_version is set by NGINX at startup and it reflects the version of the NGINX server that is currently running. This variable is derived directly from the version information found in the NGINX source code during compilation, which allows users to check the exact version of the server being used. It is commonly indicated in a format such as '1.21.0' or '1.19.10'. The variable can be accessed in various contexts within NGINX configuration files, such as in log formats or response headers. This makes it particularly useful for debugging and maintenance purposes, as administrators can quickly ascertain the version of NGINX without having to execute commands on the server. Additionally, knowing the version can be critical for ensuring compatibility with certain modules or configurations, particularly in environments where multiple NGINX instances with varying versions might exist. Overall, the $nginx_version variable serves primarily as an informational tool for both administrators and developers, providing quick access to versioning details essential for maintaining and upgrading NGINX setups.

Config Example

http {
    log_format my_log '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" NGINX/$nginx_version';
    access_log /var/log/nginx/access.log my_log;
}

Subsystem

http

Cacheable

Yes

Contexts

http, server, location, if

Ensure you are viewing the variable in the correct context, as it may not be available in all contexts.

Using it in log formats or response headers may not output the expected information if misconfigured.