Web / NGINX Interview questions
What is a location block in NGINX?
A location block, nested inside a server block, matches part of the request URI and defines how requests matching that pattern should be handled.
location /api/ { proxy_pass http://backend_app; } location /static/ { root /var/www/example; }
Matching can use an exact string (=), a prefix, or a regular expression (~ for case-sensitive, ~* for case-insensitive). NGINX evaluates exact and prefix matches first by specificity, then regex matches in the order they're written, using the first one that matches.
This lets a single server route some paths to a static file root, others to a proxied backend, and others to entirely different handling, all within one server block.
More Related questions...