0
0
Nginxdevops~20 mins

proxy_pass directive in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Proxy Pass Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the effect of this nginx configuration snippet?
Given the following nginx server block, what will be the URL requested by nginx when a client requests http://example.com/app/page?
Nginx
location /app/ {
    proxy_pass http://backend/;
}
Ahttp://backend/page
Bhttp://backend/app/page
Chttp://backend/app/
Dhttp://backend/
Attempts:
2 left
💡 Hint
Remember how nginx replaces the matching part of the URI when proxy_pass ends with a slash.
💻 Command Output
intermediate
2:00remaining
What URL does nginx request with this configuration?
Given this nginx location block, what URL will nginx request from the backend when a client requests http://example.com/app/page?
Nginx
location /app/ {
    proxy_pass http://backend;
}
Ahttp://backend/page
Bhttp://backend/app/
Chttp://backend/app/page
Dhttp://backend/
Attempts:
2 left
💡 Hint
Check if the proxy_pass URL ends with a slash or not.
Configuration
advanced
2:00remaining
Which configuration correctly forwards requests to backend preserving the original URI path?
You want nginx to forward requests from /service/ to http://backend/ so that /service/api becomes http://backend/service/api. Which proxy_pass directive achieves this?
A
location /service/ {
    proxy_pass http://backend/service;
}
B
location /service/ {
    proxy_pass http://backend/;
}
C
location /service/ {
    proxy_pass http://backend/service/;
}
D
location /service/ {
    proxy_pass http://backend;
}
Attempts:
2 left
💡 Hint
Consider how proxy_pass appends or replaces the URI based on trailing slash presence.
Troubleshoot
advanced
2:00remaining
Why does this nginx config cause a 404 error on backend?
Given this config, clients get 404 errors from backend when requesting /app/page. Why?
Nginx
location /app/ {
    proxy_pass http://backend/app/;
}
ABecause proxy_pass URL is missing a trailing slash, causing URI to be appended incorrectly
BBecause proxy_pass replaces /app/ with /app/, causing the backend to receive /app/page which may not exist
CBecause proxy_pass appends the full URI, resulting in /app/app/page sent to backend
DBecause proxy_pass URL ends with a slash, nginx removes /app/ from URI, sending /page to backend
Attempts:
2 left
💡 Hint
Check how nginx combines location and proxy_pass paths when proxy_pass has a path with trailing slash.
Best Practice
expert
2:00remaining
What is the recommended way to preserve original Host header when using proxy_pass?
You want nginx to forward requests to backend but keep the original Host header from the client. Which configuration snippet achieves this correctly?
A
proxy_set_header Host $http_host;
proxy_pass http://backend;
B
proxy_set_header Host $proxy_host;
proxy_pass http://backend;
C
proxy_set_header Host $host;
proxy_pass http://backend;
D
proxy_set_header Host backend;
proxy_pass http://backend;
Attempts:
2 left
💡 Hint
Check which variable holds the original Host header sent by the client.