# Nginx as reverse proxy for many domains (many ips in proxypass?)

**URL:** <https://www.ruby-forum.com/t/nginx-as-reverse-proxy-for-many-domains-many-ips-in-proxypass/206265>\
**Category:** NGINX\
**Created:** [April 27, 2011, 12:03am UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-for-many-domains-many-ips-in-proxypass/206265 "2011-04-27T00:03:21Z")\
**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:** [April 27, 2011, 12:03am UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-for-many-domains-many-ips-in-proxypass/206265/1 "2011-04-27T00:03:21Z")

</div>

Hi,  
I’m trying to set up nginx as a reverse proxy for several apache2  
server.  
Nginx server should act as a cache / proxy for any URL that you send -  
so  
some sort of global VirtualHost. There is no problem.  
But I do not know how to configure nginx to not only one IP address as  
the  
ProxyPass, but to automatically use the IP site (Apache2 web server -  
but  
it is different for each domain).

It is possible to do this somehow?

Thanks so much for the help.

Michal

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 27, 2011, 1:37am UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-for-many-domains-many-ips-in-proxypass/206265/2 "2011-04-27T01:37:39Z")

</div>

I’m sure there are a few different ways to accomplish this, personally  
I’m working on a dynamic method to perform this with a mysql backend.  
For a more simplistic method, maybe try using a map hash for the  
backend\_server variable that is matched against the incoming  
$http\_host:

map\_hash\_bucket\_size 64;

```
map $http_host $backend_server {
    hostnames;

    default

```

[backend-apache1.example.com](http://backend-apache1.example.com);  
[my-frontend-alias.example.com](http://my-frontend-alias.example.com)  
[vip-super-secret-backend.example.com](http://vip-super-secret-backend.example.com)  
[my-other-alias.example5.com](http://my-other-alias.example5.com)  
[vip-other-secret-backend.example2.com](http://vip-other-secret-backend.example2.com)  
}

```
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;

```

server 80 {

```
location / {

        proxy_pass http://$backend_server

}

```

}

Just an example, I’m sure I’m missing something above… 🙂

Posted at Nginx Forum:

> **[Re: nginx as reverse proxy for many domains (many ips in proxypass?)](https://forum.nginx.org/read.php?2,193908,193924#msg-193924)**
>
> Hi, I'm trying to set up nginx as a reverse proxy for several apache2 server. Nginx server should act as a cache / proxy for any URL that you send - so some sort of global VirtualHost. There is no problem. But I do not know how to configure nginx to...

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 27, 2011, 8:06am UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-for-many-domains-many-ips-in-proxypass/206265/3 "2011-04-27T08:06:03Z")

</div>

Im curious is it more efficient to use map or multiple server blocks?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 27, 2011, 2:19am UTC](https://www.ruby-forum.com/t/nginx-as-reverse-proxy-for-many-domains-many-ips-in-proxypass/206265/4 "2011-04-27T02:19:01Z")

</div>

Oops, that ‘server 80 {’ line above is completely incorrect 🙂 Take  
note…

Posted at Nginx Forum:

> **[Re: nginx as reverse proxy for many domains (many ips in proxypass?)](https://forum.nginx.org/read.php?2,193908,193936#msg-193936)**
>
> Hi, I'm trying to set up nginx as a reverse proxy for several apache2 server. Nginx server should act as a cache / proxy for any URL that you send - so some sort of global VirtualHost. There is no problem. But I do not know how to configure nginx to...
