# A question about "proxy\_redirect"

**URL:** <https://www.ruby-forum.com/t/a-question-about-proxy-redirect/209632>\
**Category:** NGINX\
**Created:** [July 19, 2011, 7:36am UTC](https://www.ruby-forum.com/t/a-question-about-proxy-redirect/209632 "2011-07-19T07:36:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [July 19, 2011, 7:36am UTC](https://www.ruby-forum.com/t/a-question-about-proxy-redirect/209632/1 "2011-07-19T07:36:06Z")

</div>

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://10.1.2.3.4:1234/redirect)  
http://$host:$server\_port;

but nginx still return “Location: [http://10.1.2.3.4:1234/redirect](http://10.1.2.3.4:1234/redirect)” to  
me.

My questions are:

1. Does proxy\_redirect only work in the case of relative URI  
redirection?
2. 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:

> **[A question about "proxy\_redirect"](https://forum.nginx.org/read.php?2,212588,212588#msg-212588)**
>
> 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

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [July 19, 2011, 7:49am UTC](https://www.ruby-forum.com/t/a-question-about-proxy-redirect/209632/2 "2011-07-19T07:49:42Z")

</div>

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](http://upservers);  
proxy\_redirect [http://upservers/](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](http://10.1.2.3:1234);  
proxy\_redirect [http://10.1.2.3:1234](http://10.1.2.3:1234) http://$host:$server\_port;  
}

Did I make some mistakes in the upstream config?

Posted at Nginx Forum:

> **[Re: A question about "proxy\_redirect"](https://forum.nginx.org/read.php?2,212588,212591#msg-212591)**
>
> 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

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [July 19, 2011, 8:11am UTC](https://www.ruby-forum.com/t/a-question-about-proxy-redirect/209632/3 "2011-07-19T08:11:18Z")

</div>

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](http://10.1.2.3.4:1234/redirect)” to  
> me.
> 
> My questions are:
> 
> 1. Does proxy\_redirect only work in the case of relative URI  
> redirection?
> 2. 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](http://10.1.2.3:1234/redirect/to/somewhere)  
and nginx has directive  
proxy\_redirect [http://10.1.2.3.4:1234/redirect](http://10.1.2.3.4:1234/redirect) /r;  
So nginx will rewrite it as  
Location: [http://nginx.server.name/r/to/somewhere](http://nginx.server.name/r/to/somewhere);

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [July 19, 2011, 8:13am UTC](https://www.ruby-forum.com/t/a-question-about-proxy-redirect/209632/4 "2011-07-19T08:13:10Z")

</div>

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](http://10.1.2.3:1234);  
> proxy\_redirect [http://10.1.2.3:1234](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/](http://upservers/)…  
but sends  
Location: [http://10.1.2.3:1234/](http://10.1.2.3:1234/)…

–  
Igor S.
