Which reason best explains why advanced NGINX configuration patterns are used for complex routing requirements?
Think about how complex rules need precise control over requests.
Advanced patterns let you combine conditions and variables to direct traffic exactly as needed, which is essential for complex routing.
What is the output when running nginx -t on this configuration snippet?
server {
listen 80;
if ($request_method = POST) {
return 405;
}
}Check if the if directive is valid inside server block.
The if directive is allowed inside server blocks, so the configuration test passes successfully.
Which configuration snippet correctly proxies requests to http://backend1 if the URI starts with /api/, otherwise to http://backend2?
Consider how to use variables and conditions to choose proxy target in one location block.
Option C uses a variable $target set conditionally, then proxies to it. This is the correct advanced pattern for conditional proxying in one location.
Given this snippet, what is the cause of the rewrite loop?
location /app/ {
rewrite ^/app/(.*)$ /$1 break;
proxy_pass http://backend;
}Think about how rewrite flags affect URI processing and loops.
The 'break' flag stops internal redirects but the rewritten URI still matches the location, causing repeated rewrites and a loop.
What is the correct order of directives to implement caching that bypasses cache for logged-in users using the $cookie_logged_in variable?
Consider the order NGINX expects cache setup and bypass directives before proxying.
First enable cache with proxy_cache, then set cache validity, then conditionally bypass cache, and finally proxy the request.