Friday 6 December 2019

NGINX: Custom variables


You can define custom variable using ‘set’ directive.

Syntax
set $app 'Chat Server';
set $version 1.23;

nginx.conf
events {
    
}


http {
    server {
        listen 9090;

        server_name localhost;

        set $app 'Chat Server';
        set $version 1.23;

        location = /aboutme {
            return 200 "Application Name: $app, \nversion: $version";
        }
    }
}


Validate and reload the configurations.
$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/aboutme’ in browser, you can see below kind of screen.

Previous                                                    Next                                                    Home

No comments:

Post a Comment