0
0
Nginxdevops~10 mins

Why location matching controls request 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 define a location block that matches requests to the root URL.

Nginx
location [1] {
    proxy_pass http://backend;
}
Drag options to blanks, or click blank then click option'
A/
B~
Croot
Ddefault
Attempts:
3 left
💡 Hint
Common Mistakes
Using '~' which is for regex matching, not root path.
Using 'root' which is not a valid location path.
2fill in blank
medium

Complete the code to match requests starting with /images/ using a prefix location.

Nginx
location [1] {
    root /var/www/images;
}
Drag options to blanks, or click blank then click option'
A/images/
B~ /images/
C^~ /images/
D/img/
Attempts:
3 left
💡 Hint
Common Mistakes
Using regex (~) when prefix match is intended.
Using a different path like '/img/' which won't match '/images/' requests.
3fill in blank
hard

Fix the error in the regex location that matches .php files.

Nginx
location [1] {
    fastcgi_pass unix:/var/run/php.sock;
}
Drag options to blanks, or click blank then click option'
A^~ \.php$
B/\.php$/
C~* \.php$
D~ \.php$
Attempts:
3 left
💡 Hint
Common Mistakes
Using ~* which is case-insensitive and may not be desired.
Using slashes around regex which nginx does not require.
4fill in blank
hard

Fill both blanks to create a location block that matches requests starting with /api/ and disables regex matching.

Nginx
location [1] [2] {
    proxy_pass http://api_backend;
}
Drag options to blanks, or click blank then click option'
A^~
B/api/
C~
D~*
Attempts:
3 left
💡 Hint
Common Mistakes
Using regex (~ or ~*) which allows regex matching.
Using just /api/ without ^~ which allows regex to override.
5fill in blank
hard

Fill the two blanks to define a location block that matches exactly /status and returns 200 with a message.

Nginx
location [1] /status {
    return [2] 'OK';
}
Drag options to blanks, or click blank then click option'
A=
B^~
C200
D~
Attempts:
3 left
💡 Hint
Common Mistakes
Using regex (~) instead of exact match (=).
Omitting the return code or using wrong code.