How can a redirect be configured in nginx to respond to a certain url with a relative redirect to a specific path?
The nginx documentation suggests that this is the default mode for nginx, but in reality if the location being redirected to starts with a / nginx is responding with an absolute url in the Location field.
For local server configuration containing locations:
location = /a {
return 301 some/path;
}
location = /b {
return 301 /qwerty;
}
the response Location to a request to /a is:
Location: some/path
and for /b it is:
Location: http://127.0.0.1/qwerty
however, we would like /b to respond with:
Location: /qwerty
The reason we would like to use relative redirects is that we would like to access nginx from different domains and proxies, e.g. in clear in dev or via ssl-terminating load-balancer, and would rather keep things simple by relieving nginx of needing to understand that context.
FYI these examples were tested against nginx versions 1.4.6 and 1.9.6, using curl e.g.:
curl --head http://127.0.0.1/b