Complete the code to define a location block that uses preferential prefix match.
location [1] /images/ {
root /data;
}The ^~ prefix tells nginx to use this location if the request URI starts with the specified prefix, skipping regex checks.
Complete the code to ensure nginx uses the preferential prefix match for /static/ requests.
location [1] /static/ {
alias /var/www/static/;
}The ^~ prefix ensures nginx uses this location for URIs starting with /static/ without checking regex locations.
Fix the error in the location block to use preferential prefix match correctly.
location [1] /api/ {
proxy_pass http://backend;
}Using ^~ ensures nginx matches the prefix /api/ preferentially, skipping regex checks.
Fill both blanks to create a preferential prefix match location and a regex location.
location [1] /downloads/ { root /data/downloads; } location [2] \.php$ { fastcgi_pass unix:/var/run/php.sock; }
The first location uses ^~ for preferential prefix match on /downloads/. The second uses ~ for regex matching PHP files.
Fill all three blanks to create a dictionary of locations with preferential prefix match and regex match conditions.
server {
listen 80;
location [1] /media/ {
root /var/media;
}
location [2] \.jpg$ {
expires 30d;
}
location [3] /favicon.ico {
log_not_found off;
}
}The ^~ prefix is for preferential prefix match on /media/. The ~ prefix is for regex matching .jpg files. The = prefix is for exact match on /favicon.ico.