# Proxy\_redirect and variables

**URL:** <https://www.ruby-forum.com/t/proxy-redirect-and-variables/185610>\
**Category:** NGINX\
**Created:** [March 23, 2010, 3:48pm UTC](https://www.ruby-forum.com/t/proxy-redirect-and-variables/185610 "2010-03-23T15:48:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobia\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e4f/32.png) [@Tobia\_C](https://www.ruby-forum.com/u/Tobia_C)\
**Post date:** [March 23, 2010, 3:48pm UTC](https://www.ruby-forum.com/t/proxy-redirect-and-variables/185610/1 "2010-03-23T15:48:56Z")

</div>

Hi

Why doesn’t proxy\_redirect interpolate variables in its first argument?

I’m trying to setup a reverse proxy to a backend that uses name-based  
virtual hosts, so I need to change both the incoming Host header and the  
outgoing Location headers:

server {  
server\_name [public.hostname.com](http://public.hostname.com);

```
set $proxy_to private.hostname.com

location / {
    proxy_pass http://backend;
    proxy_redirect http://$proxy_to/ http://$host/;
    proxy_set_header Host $proxy_to;
}

```

}

This doesn’t work, unless I expand $proxy\_to in proxy\_redirect by hand.

Am I supposed to write it in another way?

I’m using 0.8.32 on Linux amd64.

Tobia

---

<div class="post-metadata">

**Author:** ![Tobia\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e4f/32.png) [@Tobia\_C](https://www.ruby-forum.com/u/Tobia_C)\
**Post date:** [March 29, 2010, 5:31pm UTC](https://www.ruby-forum.com/t/proxy-redirect-and-variables/185610/2 "2010-03-29T17:31:15Z")

</div>

Hello

Does anybody know anything about this?

---

<div class="post-metadata">

**Author:** ![Tobia\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a88e4f/32.png) [@Tobia\_C](https://www.ruby-forum.com/u/Tobia_C)\
**Post date:** [March 29, 2010, 6:56pm UTC](https://www.ruby-forum.com/t/proxy-redirect-and-variables/185610/3 "2010-03-29T18:56:44Z")

</div>

Hello!

On Mon, Mar 29, 2010 at 05:30:19PM +0200, Tobia C. wrote:

> Does anybody know anything about this?

Yes.

> > Does anybody know why proxy\_redirect won’t interpolate variables in its first argument?

Because it doesn’t. If you think you are brave enough to change  
it - submit patches.

> > ```
> > proxy_pass http://backend;
> > proxy_redirect http://$proxy_to/ http://$host/;
> > proxy_set_header Host $proxy_to;
> > 
> > ```
> > 
> > }  
> > }
> > 
> > This doesn’t work, unless I expand $proxy\_to in proxy\_redirect  
> > by hand.
> > 
> > Am I supposed to write it in another way?

For the above config you shouldn’t use variables at all, use  
literal strings instead (and/or some config generator if you want  
to save typing). Variables are evaluated at run time and should  
be used only when they have to be different for different  
requests.

Maxim D.
