Complete the code to define a location block that matches the root URL.
location [1] {
root /var/www/html;
}The root URL is matched with / in the location block.
Complete the code to define a location block that matches URIs starting with /images/ using a prefix match.
location [1]/images/ {
root /data;
}~ which is for regex matches.= which matches exact URI only.The ^~ modifier tells nginx to use this prefix match and stop searching further.
Fix the error in the location block to correctly match URIs ending with .php using regex.
location [1] \.php$ { fastcgi_pass 127.0.0.1:9000; }
~ modifier for regex locations.^~ which is for prefix matches only.The ~ modifier is required to indicate a regex match in nginx location blocks.
Fill both blanks to create a location block that matches exact URI /favicon.ico and returns 204 status.
location [1] { return [2]; }
~ instead of exact match.404 which means not found.The = modifier matches the exact URI /favicon.ico. Returning 204 means no content.
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.
location [1] /api/ { proxy_pass [2]; proxy_set_header Host [3]; }
~ which treats the location as a regex match.The ^~ modifier tells nginx to use this prefix match and stop searching regex locations further. proxy_pass http://backend; sends requests to the backend server. $host forwards the original Host header.