# Dynamic proxy\_pass hosts

**URL:** <https://www.ruby-forum.com/t/dynamic-proxy-pass-hosts/177706>\
**Category:** NGINX\
**Created:** [October 22, 2009, 11:21am UTC](https://www.ruby-forum.com/t/dynamic-proxy-pass-hosts/177706 "2009-10-22T11:21:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 22, 2009, 11:21am UTC](https://www.ruby-forum.com/t/dynamic-proxy-pass-hosts/177706/1 "2009-10-22T11:21:57Z")

</div>

In Apache it is possible to dynamically alter the proxy\_pass remote  
host, i.e. like this

RewriteRule ^/proxy\_everything/(.\*)$ http://$1 [P]

So I cant extract the host from the URI, or from the environment  
variable etc.

Is it possible to do the same with nginx?

Thanks in advance,  
Igor K…

---

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 22, 2009, 12:07pm UTC](https://www.ruby-forum.com/t/dynamic-proxy-pass-hosts/177706/2 "2009-10-22T12:07:02Z")

</div>

Hello!

On Thu, Oct 22, 2009 at 01:17:16PM +0400, Igor K. wrote:

> In Apache it is possible to dynamically alter the proxy\_pass remote  
> host, i.e. like this
> 
> RewriteRule ^/proxy\_everything/(.\*)$ http://$1 [P]
> 
> So I cant extract the host from the URI, or from the environment  
> variable etc.
> 
> Is it possible to do the same with nginx?

Yes, proxy\_pass supports variables since 0.6.18. Note that you  
must have resolver defined in nginx config if possible upstream  
hosts include arbitrary hostnames (i.e. not only ip addresses and  
names defined via upstream{} blocks).

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Note that wiki topics are a bit garbled, probably it’s a good idea  
to consult original docs too (use google translate if you don’t  
know Russian):

> **[Модуль ngx\_http\_proxy\_module](http://nginx.org/ru/docs/http/ngx_http_proxy_module.html)**

> **[Модуль ngx\_http\_core\_module](http://nginx.org/ru/docs/http/ngx_http_core_module.html)**

Maxim D.

---

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 22, 2009, 2:00pm UTC](https://www.ruby-forum.com/t/dynamic-proxy-pass-hosts/177706/3 "2009-10-22T14:00:01Z")

</div>

Maxim D. wrote:

> > variable etc.
> 
> Note that wiki topics are a bit garbled, probably it’s a good idea  
> to consult original docs too (use google translate if you don’t  
> know Russian):
> 
> [Модуль ngx\_http\_proxy\_module](http://sysoev.ru/nginx/docs/http/ngx_http_proxy_module.html#proxy_pass)  
> [Модуль ngx\_http\_core\_module](http://sysoev.ru/nginx/docs/http/ngx_http_core_module.html#resolver)
> 
> Maxim D.

Thanks, Maxim! Well, I am russian, so I can read the docs. Are they more  
up-to-date or detailed? I usually read the wiki

---

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 22, 2009, 2:55pm UTC](https://www.ruby-forum.com/t/dynamic-proxy-pass-hosts/177706/4 "2009-10-22T14:55:38Z")

</div>

Hello!

On Thu, Oct 22, 2009 at 03:51:41PM +0400, Igor K. wrote:

> > > So I cant extract the host from the URI, or from the environment  
> > > [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpCoreModule#resolver)  
> > > Thanks, Maxim! Well, I am russian, so I can read the docs. Are they  
> > > more up-to-date or detailed? I usually read the wiki

The problem with wiki is that it’s rarely synced with official  
docs and may be seriously out of date. Additionally as it’s wiki  
it’s regularly edited by users who ofter unaware how things really  
work, and this results in wrong/misleading information in many cases.

In this particular case proxy\_pass description in wiki has no full  
documentation on proxy\_pass work with variables (it has some  
user-contributed content about variables in proxy\_pass, but  
written from completely different and wrong point of view), while  
resolver just has no description.

Maxim D.
