If the backend server uses FULL URL to initiate a redirect, like
sendRedirect("http://10.1.2.3:1234/redirect");
Can proxy_redirect match this URL and do the redirect?
I write this in config but it seems doesn’t work:
proxy_redirect http://10.1.2.3.4:1234/redirect
http://$host:$server_port;
but nginx still return “Location: http://10.1.2.3.4:1234/redirect” to
me.
My questions are:
- Does proxy_redirect only work in the case of relative URI
redirection?
- How should I do if I want to convert the backend server’s host in the
FULL URL redirection case?
Thanks.
Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,212588,212588#msg-212588
I find that if I uses proxy_pass to an upstream, the FULL URL match will
fail:
upstream upservers {
server 10.1.2.3:1234;
}
location / {
proxy_pass http://upservers;
proxy_redirect http://upservers/ http://$host:$server_port;
}
However, if I directly proxy_pass to the backend, it works:
location / {
proxy_pass http://10.1.2.3:1234;
proxy_redirect http://10.1.2.3:1234 http://$host:$server_port;
}
Did I make some mistakes in the upstream config?
Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,212588,212591#msg-212591
On Tue, Jul 19, 2011 at 01:35:17AM -0400, speedfirst wrote:
but nginx still return “Location: http://10.1.2.3.4:1234/redirect” to
me.
My questions are:
- Does proxy_redirect only work in the case of relative URI
redirection?
- How should I do if I want to convert the backend server’s host in the
FULL URL redirection case?
nginx uses prefix for redirect. For example, if backend sends
Location: http://10.1.2.3:1234/redirect/to/somewhere
and nginx has directive
proxy_redirect http://10.1.2.3.4:1234/redirect /r;
So nginx will rewrite it as
Location: http://nginx.server.name/r/to/somewhere;
–
Igor S.
On Tue, Jul 19, 2011 at 01:48:53AM -0400, speedfirst wrote:
}
However, if I directly proxy_pass to the backend, it works:
location / {
proxy_pass http://10.1.2.3:1234;
proxy_redirect http://10.1.2.3:1234 http://$host:$server_port;
}
Did I make some mistakes in the upstream config?
No. I believe your backend does not send
Location: http://upservers/…
but sends
Location: http://10.1.2.3:1234/…
–
Igor S.