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

I’m trying to set up nginx as a reverse proxy for several apache2
Nginx server should act as a cache / proxy for any URL that you send -
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
ProxyPass, but to automatically use the IP site (Apache2 web server -
it is different for each domain).

It is possible to do this somehow?

Thanks so much for the help.


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

map_hash_bucket_size 64;

map $http_host $backend_server {


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… :slight_smile:

Posted at Nginx Forum:

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

Oops, that ‘server 80 {’ line above is completely incorrect :slight_smile: Take

Posted at Nginx Forum: