0
0
Nginxdevops~10 mins

Preferential prefix match (^~) 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 uses preferential 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 match.
Using '=' which is for exact match.
Using '~*' which is case-insensitive regex match.
2fill in blank
medium

Complete the code to ensure nginx uses the preferential prefix match for /static/ requests.

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

Fix the error in the location block to use preferential prefix match correctly.

Nginx
location [1] /api/ {
    proxy_pass http://backend;
}
Drag options to blanks, or click blank then click option'
A^~
B~
C=
D~*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '~' or '~*' which are regex matches and do not guarantee prefix priority.
Using '=' which is for exact matches.
4fill in blank
hard

Fill both blanks to create a preferential prefix match location and a regex location.

Nginx
location [1] /downloads/ {
    root /data/downloads;
}

location [2] \.php$ {
    fastcgi_pass unix:/var/run/php.sock;
}
Drag options to blanks, or click blank then click option'
A^~
B~
C=
D~*
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the prefixes causing wrong matching behavior.
Using '=' for regex location.
5fill in blank
hard

Fill all three blanks to create a dictionary of locations with preferential prefix match and regex match conditions.

Nginx
server {
    listen 80;

    location [1] /media/ {
        root /var/media;
    }

    location [2] \.jpg$ {
        expires 30d;
    }

    location [3] /favicon.ico {
        log_not_found off;
    }
}
Drag options to blanks, or click blank then click option'
A^~
B~
C=
D~*
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up regex and prefix match prefixes.
Using '~*' instead of '~' for case-sensitive regex.