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

No comments:

Post a Comment