# Upsteam + proxy\_redirect?

**URL:** <https://www.ruby-forum.com/t/upsteam-proxy-redirect/208195>\
**Category:** NGINX\
**Created:** [June 11, 2011, 11:22pm UTC](https://www.ruby-forum.com/t/upsteam-proxy-redirect/208195 "2011-06-11T23:22:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 11, 2011, 11:22pm UTC](https://www.ruby-forum.com/t/upsteam-proxy-redirect/208195/1 "2011-06-11T23:22:03Z")

</div>

Hi,  
here is part of nginx.conf ; in some condition [mysite1.com](http://mysite1.com) redirect  
users  
to some of its url so i need to use proxy\_redirect in my locations;

now i want to start using upstream to add load balancing to my site;

the location v1 is working fine with my main site but when i want to  
change its setting to something like location v2 it does not work and  
redirect browser to [mysite1.com](http://mysite1.com) and users can see the real site behind  
the [mynginxserver.com](http://mynginxserver.com)

can i use proxy\_redirect when i use upstream ??

users type [myngixxserver.com](http://myngixxserver.com) in their browser;  
images stores on [mysite2.com](http://mysite2.com);  
i will add more server to my upstream when the problem solves;  
sorry for my bad english  
mystic and mysite2 ip addresses are invalid

if more info is needed plaza tel me  
thank you in advance;

* * *

upstream mysites {  
server [www.mysite1.com](http://www.mysite1.com);  
}

upstream myimages {  
server [image.mysite1.com](http://image.mysite1.com);  
}  
location /v1 {  
proxy\_pass [http://www.mysite1.com](http://www.mysite1.com);  
proxy\_redirect [http://www.mysite1.com/v1](http://www.mysite1.com/v1)  
[NameBright - Coming Soon](http://www.mynginxserver.com/v1)  
}

location /v2 {  
proxy\_pass [http://mysites/v2](http://mysites/v2);  
proxy\_redirect [http://www.mysite1.com](http://www.mysite1.com)  
[NameBright - Coming Soon](http://www.mynginxserver.com/v2);  
}

location /images {  
proxy\_pass [http://www.mysite2.com/images](http://www.mysite2.com/images);  
}

Posted at Nginx Forum:

> **[upsteam + proxy\_redirect ??](https://forum.nginx.org/read.php?2,206003,206003#msg-206003)**
>
> Hi, here is part of nginx.conf ; in some condition mysite1.com redirect users to some of its url so i need to use proxy\_redirect in my locations; now i want to start using upstream to add load balancing to my site; the location v1 is working fine...

---

<div class="post-metadata">

**Author:** ![torajx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@torajx](https://www.ruby-forum.com/u/torajx)\
**Post date:** [June 14, 2011, 10:23am UTC](https://www.ruby-forum.com/t/upsteam-proxy-redirect/208195/2 "2011-06-14T10:23:58Z")

</div>

Hello!

On Tue, Jun 14, 2011 at 03:24:52AM -0400, torajx wrote:

> if any more info needed plz tell me;  
> why v1 works but v2 does not ???

Try looking what your backend actually returns in ‘Location’  
header.

Maxim D.

---

<div class="post-metadata">

**Author:** ![torajx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@torajx](https://www.ruby-forum.com/u/torajx)\
**Post date:** [June 14, 2011, 9:25am UTC](https://www.ruby-forum.com/t/upsteam-proxy-redirect/208195/3 "2011-06-14T09:25:16Z")

</div>

if any more info needed plz tell me;  
why v1 works but v2 does not ???

Posted at Nginx Forum:

> **[Re: upsteam + proxy\_redirect ??](https://forum.nginx.org/read.php?2,206003,206652#msg-206652)**
>
> Hi, here is part of nginx.conf ; in some condition mysite1.com redirect users to some of its url so i need to use proxy\_redirect in my locations; now i want to start using upstream to add load balancing to my site; the location v1 is working fine...

---

<div class="post-metadata">

**Author:** ![torajx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@torajx](https://www.ruby-forum.com/u/torajx)\
**Post date:** [June 14, 2011, 12:04pm UTC](https://www.ruby-forum.com/t/upsteam-proxy-redirect/208195/4 "2011-06-14T12:04:05Z")

</div>

thank you, i will try; but what is different between v1 and v2 ;  
i just use upstream in v2 and server in upstream is the same as v1  
server;

thank you

Posted at Nginx Forum:

> **[Re: upsteam + proxy\_redirect ??](https://forum.nginx.org/read.php?2,206003,206675#msg-206675)**
>
> Hi, here is part of nginx.conf ; in some condition mysite1.com redirect users to some of its url so i need to use proxy\_redirect in my locations; now i want to start using upstream to add load balancing to my site; the location v1 is working fine...

---

<div class="post-metadata">

**Author:** ![torajx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@torajx](https://www.ruby-forum.com/u/torajx)\
**Post date:** [June 14, 2011, 1:26pm UTC](https://www.ruby-forum.com/t/upsteam-proxy-redirect/208195/5 "2011-06-14T13:26:57Z")

</div>

Hello!

On Tue, Jun 14, 2011 at 06:03:52AM -0400, torajx wrote:

> thank you, i will try; but what is different between v1 and v2 ;  
> i just use upstream in v2 and server in upstream is the same as v1  
> server;

The difference is upstream name: in v1 you use your domain (the  
same as in proxy\_redirect), while in v2 you use upstream{} block  
name. Upstream name is used in Host header in request to upstream  
by default[1], and this may (and likely will) cause your backend  
to return different redirects.

BTW, proxy\_redirect default will use upstream name as well, and  
this should handle such situations transparently. See [2] for  
details.

[1] [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpProxyModule#proxy_set_header)  
[2] [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpProxyModule#proxy_redirect)

Maxim D.

---

<div class="post-metadata">

**Author:** ![torajx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@torajx](https://www.ruby-forum.com/u/torajx)\
**Post date:** [June 14, 2011, 4:25pm UTC](https://www.ruby-forum.com/t/upsteam-proxy-redirect/208195/6 "2011-06-14T16:25:55Z")

</div>

thank you;  
I checked proxy\_redirect default; in v2 but it did not worked;  
but i try to check everything again;

Posted at Nginx Forum:

> **[Re: upsteam + proxy\_redirect ??](https://forum.nginx.org/read.php?2,206003,206746#msg-206746)**
>
> Hi, here is part of nginx.conf ; in some condition mysite1.com redirect users to some of its url so i need to use proxy\_redirect in my locations; now i want to start using upstream to add load balancing to my site; the location v1 is working fine...

---

<div class="post-metadata">

**Author:** ![torajx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@torajx](https://www.ruby-forum.com/u/torajx)\
**Post date:** [June 15, 2011, 7:38am UTC](https://www.ruby-forum.com/t/upsteam-proxy-redirect/208195/7 "2011-06-15T07:38:01Z")

</div>

Hiiiiiiiiiiiiiiii,

the problem solved with :  
proxy\_set\_header Host [www.mysite1.com](http://www.mysite1.com);

thank you very much;

Posted at Nginx Forum:

> **[Re: upsteam + proxy\_redirect ??](https://forum.nginx.org/read.php?2,206003,207019#msg-207019)**
>
> Hi, here is part of nginx.conf ; in some condition mysite1.com redirect users to some of its url so i need to use proxy\_redirect in my locations; now i want to start using upstream to add load balancing to my site; the location v1 is working fine...

---

<div class="post-metadata">

**Author:** ![torajx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@torajx](https://www.ruby-forum.com/u/torajx)\
**Post date:** [June 15, 2011, 9:19am UTC](https://www.ruby-forum.com/t/upsteam-proxy-redirect/208195/8 "2011-06-15T09:19:59Z")

</div>

hi again  
only one question left;  
i want to add more server to my upstream;  
i tried to use this :  
proxy\_set\_header Host $upstream\_addr;

but $upstream\_addr contains port of upstream server too;  
i did not find any thing yet to remove port from $upstream\_addr;  
how can i do it ?

thanks again

Posted at Nginx Forum:

> **[Re: upsteam + proxy\_redirect ??](https://forum.nginx.org/read.php?2,206003,207030#msg-207030)**
>
> Hi, here is part of nginx.conf ; in some condition mysite1.com redirect users to some of its url so i need to use proxy\_redirect in my locations; now i want to start using upstream to add load balancing to my site; the location v1 is working fine...
