Support for relative URL in Location header

Jeroen Ooms jeroen.ooms at stat.ucla.edu
Mon Nov 4 18:42:00 UTC 2013


HTTP status codes such as 201, 301, 302, etc rely on the HTTP Location
header. The current standard of HTTP specifies that this URL must be
absolute. However, all popular browsers will accept a relative URL,
and it is correct according to the upcoming revision of HTTP/1.1. See
also [1].

I noticed that the version of nginx that I'm running (1.1.9, ubuntu
precise) does not properly interpret a relative URL. The docs on
"proxy_redirect" state that "The default replacement specified by the
default parameter uses the parameters of the location and proxy_pass
directives. " [2]. However it does not work when the Location path is
relative. For example if:

location /one/ {
    proxy_pass     http://upstream:port/two/;
    proxy_redirect default;
}

Then a location header "http://upstream:port/two/foo.bar" gets
rewritten to "/one/foo.bar". However a location header "/two/foo.bar"
does not get rewritten to "/one/foo.bar", as it should if the relative
URL were supported.

Is this something that will, or already has been implemented in more
recent versions of nginx?



[1] http://en.wikipedia.org/wiki/HTTP_location#Relative_URL_example
[2] http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect



More information about the nginx mailing list