0
0
Nginxdevops~10 mins

Nested 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 basic location block for 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 location.
2fill in blank
medium

Complete the code to define a nested location block that matches URLs starting with /images/.

Nginx
location / {
    location [1] {
        root /var/www/images;
    }
}
Drag options to blanks, or click blank then click option'
A/img/
B/pics/
C/images/
D/static/
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect path prefixes like /img/ or /pics/.
3fill in blank
hard

Fix the error in the nested location block to correctly match URLs ending with .php.

Nginx
location /app/ {
    location [1] {
        fastcgi_pass unix:/var/run/php-fpm.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 unescaped dots or wrong regex modifiers.
4fill in blank
hard

Fill both blanks to create a nested location block that matches /api/ and proxies requests to a backend server.

Nginx
location [1] {
    location [2] {
        proxy_pass http://backend_server;
    }
}
Drag options to blanks, or click blank then click option'
A/api/
B/backend/
C/v1/
D/service/
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the outer and inner location paths.
5fill in blank
hard

Fill all three blanks to define nested location blocks for /app/, /static/, and /images/ with appropriate root directories.

Nginx
location [1] {
    location [2] {
        root /var/www/static;
    }
    location [3] {
        root /var/www/images;
    }
}
Drag options to blanks, or click blank then click option'
A/app/
B/static/
C/images/
D/assets/
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect paths or mixing root directories.