Complete the code to route requests to version 1 of the API.
location /api/v1/ {
proxy_pass http://backend[1];
}The proxy_pass directive must include the trailing slash to correctly forward the URI after /api/v1/.
Complete the code to route requests to version 2 of the API.
location /api/v2/ {
proxy_pass http://backend[1];
}Requests to /api/v2/ should be proxied to the backend's /v2/ path with a trailing slash.
Fix the error in the location block to correctly route to version 1 API.
location /api/v1 {
proxy_pass http://backend[1];
}The location block must end with a slash to match the path correctly, and proxy_pass must include the trailing slash.
Fill both blanks to route requests to version 3 API and set a custom header.
location /api/v3/ {
proxy_pass http://backend[1];
proxy_set_header X-API-Version [2];
}The proxy_pass must point to /v3/ to route correctly, and the header should reflect the API version "v3".
Fill all three blanks to create a map for API version routing and use it in proxy_pass.
map $uri $backend_path {
~^/api/v1/ /v1/;
~^/api/v2/ /v2/;
default [1];
}
location /api/ {
proxy_pass http://backend[2];
proxy_set_header X-API-Version [3];
}The default path in the map is /v3/ for other versions, proxy_pass uses the mapped variable $backend_path, and the header is set to "dynamic" to indicate dynamic routing.