0
0
Nginxdevops~10 mins

Why URL manipulation handles routing in Nginx - Test Your Understanding

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

Complete the code to rewrite the URL path to /home.

Nginx
rewrite [1] /home break;
Drag options to blanks, or click blank then click option'
A^/oldpath$
B/oldpath$
C/oldpath
D^oldpath$
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the ^ and $ causes partial matches.
Missing the leading slash in the pattern.
2fill in blank
medium

Complete the code to redirect all requests from /old to /new permanently.

Nginx
return [1] /new;
Drag options to blanks, or click blank then click option'
A302
B301
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 302 instead of 301 causes temporary redirect behavior.
Using 404 or 500 causes errors instead of redirect.
3fill in blank
hard

Fix the error in the location block to match URLs starting with /app.

Nginx
location [1] {
    proxy_pass http://backend;
}
Drag options to blanks, or click blank then click option'
A^/app/
B~ /app
C/app
D^/app
Attempts:
3 left
💡 Hint
Common Mistakes
Using /app matches unintended paths like /appfoo.
Using ~ /app treats it as a regex but without anchors.
4fill in blank
hard

Fill both blanks to create a map that sets $target to /index.html if $uri is /, else $uri.

Nginx
map $uri $target {
    [1] /index.html;
    [2] $uri;
}
Drag options to blanks, or click blank then click option'
A"/"
B"/index.html"
Cdefault
D~^/
Attempts:
3 left
💡 Hint
Common Mistakes
Using regex (~) instead of exact string match.
Missing the default case causes errors for other URLs.
5fill in blank
hard

Fill all three blanks to rewrite URLs starting with /blog to /posts and set permanent redirect.

Nginx
location [1] {
    rewrite [2] /posts/$1 [3];
}
Drag options to blanks, or click blank then click option'
A^/blog/
B^/blog/(.*)$
C/posts/$1
Dpermanent
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the capture group causes loss of path info.
Using 'break' instead of 'permanent' does not redirect.