What is Nginx variables ?
Nginx Tutorial
Nginx variables are holding values within the Nginx configuration file.
Nginx offers two types of variables:
1. System Variables (Predefined Variables):
System variables defined by Nginx
Examples of system variables include `$http_host`, which holds the value of the “Host” header sent by the client, and `$request_uri`, which contains the original request URI.
System variables are accessible anywhere inside the config file.
2. User-Defined Variables:
Created by the administrator/Network Admin/ Devops etc.
They are prefixed with the ‘$’ symbol followed by a name
such as ‘$my_variable‘.// anythingh you can mention instead of my_variable
These variables can be used in different parts of the configuration file and can be used for different purposes
List of Nginx system variables
| Variable | Description |
| $args | The arguments of the request as a query string |
| $request_uri | The original request URI, including the query string |
| $http_<header> | The value of an HTTP request header, where <header> is the header name in lowercase, with hyphens replaced by underscores |
| $sent_http_<header> | The value of an HTTP response header, where <header> is the header name in lowercase, with hyphens replaced by underscores |
| $query_string | The query string portion of the request URI |
| $remote_addr | The IP address of the client making the request |
| $server_name | The server name as specified in the server block |
| $request_method | The HTTP request method (GET, POST, etc.) |
| $uri | The request URI without the query string |
| $document_root | The root directory of the Nginx server |
| $hostname | The hostname of the server (requires the ngx_http_core_module) |
| $server_port | The port number on which the server is listening |
| $ssl_protocol | The SSL/TLS protocol version used in the connection |
| $ssl_cipher | The SSL/TLS cipher suite used in the connection |
| $request_filename | The file path being accessed by the request |
| $args_<name> | The value of a query string parameter, where <name> is the parameter name |
| $cookie_<name> | The value of a cookie, where <name> is the cookie name |
| $http_user_agent | The user agent string of the client making the request |
| $http_referer | The referer URL from which the request originated |
| $upstream_http_<header> | The value of an HTTP response header from an upstream server, where <header> is the header name in lowercase, with hyphens replaced by underscores |
These are just a few examples of the many variables available in Nginx.


