Saturday 30 November 2019

NGINX: location: Prefix match

location /welcome {
 return 200 "Hey, welcome to NGINX";
}


Above snippet match any url that starts with welcome string


nginx.conf
events {
    
}

http {
    server {
        listen 9090;

        server_name localhost;

        location /welcome {
            return 200 "Hey, welcome to NGINX";
        }
    }
}


Validate and reload the configurations.
$sudo nginx -t
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' in browser, you can see below screen.

Since it is a prefix match, any url starts with welcome will be served

For example, you will get same response for following urls.
http://localhost:9090/welcome/ram
http://localhost:9090/welcome/1/2/3/siva

Previous                                                    Next                                                    Home

No comments:

Post a Comment