Hint: Use 'location' keyword with path and braces [OK]
Common Mistakes:
Using 'route' or 'path' instead of 'location'
Confusing 'server' block with 'location' block
Missing braces or semicolons in syntax
3. Given this nginx config snippet:
location /images/ {
root /var/www/html;
}
What file path will nginx serve for a request to /images/logo.png?
medium
A. /images/logo.png
B. /var/www/html/logo.png
C. /var/www/html/images/logo.png
D. /var/www/logo.png
Solution
Step 1: Understand nginx root with location
The root directive appends the full request URI to the root path.
Step 2: Combine root and URI
Request URI is /images/logo.png. Root is /var/www/html. So full path is /var/www/html/images/logo.png.
Final Answer:
/var/www/html/images/logo.png -> Option C
Quick Check:
root + full URI = /var/www/html/images/logo.png [OK]
Hint: root + full URI = file path served [OK]
Common Mistakes:
Removing the /images/ part from the path
Confusing root with alias directive
Assuming root replaces the URI
4. You have this nginx config:
location /app/ {
proxy_pass http://backend/;
}
Requests to /app/page return 404. What is the likely cause?
medium
A. location block syntax error
B. Missing root directive in location block
C. Incorrect server block name
D. Trailing slash in proxy_pass causes URL to be replaced incorrectly
Solution
Step 1: Understand proxy_pass with trailing slash
When proxy_pass ends with a slash, nginx replaces the matching part of the URL with the proxy URL path.
Step 2: Analyze URL rewriting effect
Request /app/page matches /app/. Because proxy_pass has trailing slash, nginx sends request as /page to backend. If backend expects /app/page, it returns 404.
Final Answer:
Trailing slash in proxy_pass causes URL to be replaced incorrectly -> Option D
Quick Check:
proxy_pass trailing slash changes URL [OK]
Hint: Trailing slash in proxy_pass rewrites URL path [OK]
Common Mistakes:
Thinking root directive is needed with proxy_pass
Blaming server block name instead of URL rewrite
Assuming syntax error without checking proxy_pass
5. You want nginx to route requests to /api/v1/ to http://backend/v1/ but keep the rest of the URL unchanged. Which config correctly handles this?
hard
A. location /api/v1/ { proxy_pass http://backend/; }
B. location /api/v1/ { proxy_pass http://backend/v1/; }
C. location /api/v1/ { proxy_pass http://backend; }
D. location /api/v1/ { proxy_pass http://backend/api/v1/; }
Solution
Step 1: Understand proxy_pass URI replacement
When proxy_pass has a URI ending in /, nginx replaces the matched location prefix with the proxy_pass URI and appends the remaining path.
Step 2: Match requirement to config
location /api/v1/ { proxy_pass http://backend/v1/; }: proxy_pass http://backend/v1/; replaces /api/v1/ with /v1/, so /api/v1/resource becomes http://backend/v1/resource.
Final Answer:
location /api/v1/ { proxy_pass http://backend/v1/; } -> Option B
Quick Check:
proxy_pass with replacement URI rewrites prefix [OK]
Hint: proxy_pass trailing / with path replaces location prefix [OK]
Common Mistakes:
Adding trailing slash rewrites and drops part of URL
Duplicating path segments in proxy_pass
Using wrong proxy_pass URL causing 404
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.