Introduction
A web application serves the users when they send an HTTP request for the information or access they need. It responds to every request it receives. But what if the requests are sent by bots and any vulnerable scripts? The application definitely needs a server to find these requests and terminate them in such cases. But do we have a server like that?
Definitely yes. We have a server, ‘NGINX’. NGINX is an open-source, high-performance web server used to serve static files. The bots often send server requests using IP addresses, while users(humans) do it using hostnames. NGINX analyses the requests sent to the applications using IP addresses and terminates them after verifying they are bots. This improves the content of application, security, and facilitates scalability and availability for crowded websites on the internet. It provides various services like a load balancer, reverse proxy, and rate limit network. Let’s learn about NGINX variables and how to use them.
Also see, Must Do Coding Questions
NGINX variables
A variable is a storage location of any value to be used or referenced by programs. In other words, a variable stores the values that we need throughout the program and allows us to use them in any context when necessary. In programming languages like C, C#, C++, Java, etc., we use variables, and they can hold any type of values like numbers, strings, arrays, etc. But in NGINX, the variables can hold only a single type of value, i.e., String. The syntax of the variables is as follows.
set $str "coding ninjas";
The variable $str in the above syntax is set to a value “coding ninjas” and the symbol $ is used to add a reference to the variables. It is necessary to add the dollar sign($) as a prefix to variables. We can set the value of the String to a variable without the quotes too. Both the ways are fine and work as intended.
set $str coding ninjas;
In NGINX, we can assign a variable to another variable, just like in other programming languages. This technique is called “variable interpolation”.
set $str college;
set $str1 “$str2”;The value college is assigned to the variable $str in the above code, and the variable $str1 is assigned to variable $str2. So the value of $str2 will be “college” as well. We can also set the variable's value by concatenating the variable and a string.
set $a “hello”;
set $b “${a} world”;
The variable $b in the above code now contains the value hello world, and $a contains hello.
Let’s explore few variables in NGINX along with their description.
Recommended Topic - Ibegin TCS
| Variable | Description |
| $arg_name | Name of the arguments in request line. |
| $args | List of arguments in the request line. |
| $connection | The connection serial number |
| $cookie_name | Name of the cookie |
| $date_gmt | Current time in GMT (Greenwich Mean Time). |
| $date_local | Current time in the user’s local time zone |
| $geoip_latitude | Latitude of given place/location |
| $geoip_longitude | Longitude of given place/location |
| $host | Hostname from the request line or header |
| $request | Original request line. |
| $session_time | Session duration in seconds |
These are few commonly used variables in NGINX and their descriptions. We have many other variables too, which are used according to the necessity in code.
You can also read about mock interview.
Recommended Topic, 8085 Microprocessor Pin Diagram




