Tuesday, 3 December 2019

NGINX specific variables demo


NGINX has several built in variables to get host details, uri, local date etc.,

You can get complete list of pre-defined variables from below location.

nginx.conf
events {
    
}

http {
    server {
        listen 9090;

        server_name localhost;

        location = /welcome {
            return 200 "Host: $host, \nuri: $uri, \nargs: $args, \ndate: $date_local";
        }
    }
}


Validate and reload the configuration file.
$sudo nginx -t
Password:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
$
$sudo nginx -s reload


Open the url ‘http://localhost:9090/welcome?name=krishna&age=30’ in browser, you can see below screen.


Previous                                                    Next                                                    Home

NGINX: Variables


There are two kinds of variables exist in NGINX.
a.   NGINX specific variables
b.   Custom variables

NGINX specific variables
You can get all the NGINX specific variables at below location.

Custom variables
As a user, you can define variables and use them.




Previous                                                    Next                                                    Home