0
0
Nginxdevops~10 mins

API routing with location blocks in Nginx - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a location block for the API path.

Nginx
location [1] {
    proxy_pass http://backend_api;
}
Drag options to blanks, or click blank then click option'
A/api
B/home
C/static
D/images
Attempts:
3 left
💡 Hint
Common Mistakes
Using a path unrelated to API like /home or /static.
2fill in blank
medium

Complete the code to proxy API requests to the backend server.

Nginx
location /api {
    proxy_pass [1];
}
Drag options to blanks, or click blank then click option'
Ahttp://frontend_server
Bhttp://localhost:80
Chttp://backend_api
Dhttps://external_site
Attempts:
3 left
💡 Hint
Common Mistakes
Proxying to the frontend or unrelated servers.
3fill in blank
hard

Fix the error in the location block to correctly match all API requests including subpaths.

Nginx
location [1] {
    proxy_pass http://backend_api;
}
Drag options to blanks, or click blank then click option'
A/api/*
B/api
C~ /api
D/api/
Attempts:
3 left
💡 Hint
Common Mistakes
Using regex (~) without proper syntax or using wildcard * which is invalid in location.
4fill in blank
hard

Fill both blanks to rewrite the URL path before proxying to backend.

Nginx
location /api/ {
    proxy_pass http://backend_api[1];
    rewrite [2] $1 break;
}
Drag options to blanks, or click blank then click option'
A/v1/
B^/api/(.*)$
C/
D/v1
Attempts:
3 left
💡 Hint
Common Mistakes
Using trailing slash in proxy_pass causing double slashes.
Incorrect regex in rewrite directive.
5fill in blank
hard

Fill all three blanks to create a location block that proxies /api requests to backend and sets a custom header.

Nginx
location [1] {
    proxy_pass [2];
    proxy_set_header [3] "API-Request";
}
Drag options to blanks, or click blank then click option'
A/api/
Bhttp://backend_api
CX-Custom-Header
D/api
Attempts:
3 left
💡 Hint
Common Mistakes
Missing trailing slash in location causing partial matches.
Wrong header name or missing proxy_pass.