Support for relative URL in Location header

Maxim Dounin mdounin at mdounin.ru
Tue Nov 5 01:08:02 UTC 2013


Hello!

On Mon, Nov 04, 2013 at 10:42:00AM -0800, Jeroen Ooms wrote:

> 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;
> }

Docs explicity say that this is equivalent to

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

Note that it just illustrates what the sentence you've quoted 
means.

> 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?

The proxy_redirect directive does string replacement, not URI 
mapping.  If you want it to replace "/two/" with "/one/", you can 
configure it to do so.  It's just not something it does by 
default.

-- 
Maxim Dounin
http://nginx.org/en/donation.html



More information about the nginx mailing list