0
0
Nginxdevops~10 mins

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 that matches the root URL.

Nginx
location [1] {
    root /var/www/html;
}
Drag options to blanks, or click blank then click option'
A~
B^~
C/
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using regex modifiers like ~ or ^~ for the root path.
Using = which matches exact URI only.
2fill in blank
medium

Complete the code to define a location block that matches URIs starting with /images/ using a prefix match.

Nginx
location [1]/images/ {
    root /data;
}
Drag options to blanks, or click blank then click option'
A/
B^~
C~
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using ~ which is for regex matches.
Using = which matches exact URI only.
3fill in blank
hard

Fix the error in the location block to correctly match URIs ending with .php using regex.

Nginx
location [1] \.php$ {
    fastcgi_pass 127.0.0.1:9000;
}
Drag options to blanks, or click blank then click option'
A~
B/
C^~
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the ~ modifier for regex locations.
Using ^~ which is for prefix matches only.
4fill in blank
hard

Fill both blanks to create a location block that matches exact URI /favicon.ico and returns 204 status.

Nginx
location [1] {
    return [2];
}
Drag options to blanks, or click blank then click option'
A= /favicon.ico
B204
C404
D~ /favicon.ico
Attempts:
3 left
💡 Hint
Common Mistakes
Using regex modifier ~ instead of exact match.
Returning 404 which means not found.
5fill in blank
hard

Fill all three blanks to create a location block that matches URIs starting with /api/ using a prefix match modifier, and proxies requests to http://backend.

Nginx
location [1] /api/ {
    proxy_pass [2];
    proxy_set_header Host [3];
}
Drag options to blanks, or click blank then click option'
A~
Bhttp://backend
C$host
D^~
Attempts:
3 left
💡 Hint
Common Mistakes
Using ~ which treats the location as a regex match.
Not forwarding the Host header correctly.