# Nginx reverse proxy with IP-Based vhosts apache

**URL:** <https://www.ruby-forum.com/t/nginx-reverse-proxy-with-ip-based-vhosts-apache/126448>\
**Category:** NGINX\
**Created:** [January 18, 2008, 10:43am UTC](https://www.ruby-forum.com/t/nginx-reverse-proxy-with-ip-based-vhosts-apache/126448 "2008-01-18T10:43:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [January 18, 2008, 10:43am UTC](https://www.ruby-forum.com/t/nginx-reverse-proxy-with-ip-based-vhosts-apache/126448/1 "2008-01-18T10:43:15Z")

</div>

Hi,

I’m looking for comments on my nginx.conf file. I am using nginx to  
serve  
some static content and proxy to apache for some other requests however  
I  
think there is something wrong with my proxypass settings.

If I use apache’s name based virtual hosts everything works out great,  
however if I use IP based virtual hosts, apache does not direct to the  
right  
virtual host, instead just defaulting to the main Document Root. I can’t  
seem to find an answer on Google anywhere, so any feedback is greatly  
appreciated (relevant part of nginx.conf below).

```
    location / {
        proxy_pass http://127.0.0.1:8080/;
        proxy_redirect off;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For 

```

$proxy\_add\_x\_forwarded\_for;

```
        client_max_body_size 10m;
        client_body_buffer_size 128k;

        proxy_connect_timeout 90;
        proxy_send_timeout 90;
        proxy_read_timeout 90;

        proxy_buffer_size 4k;
        proxy_buffers 4 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
    }
```

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [January 18, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/nginx-reverse-proxy-with-ip-based-vhosts-apache/126448/2 "2008-01-18T18:04:46Z")

</div>

Hello,

this seems more an apache issue.  
Have you got a proper NameVirtualHost directive ?  
(e.g. NameVirtualHost \*:8080 )

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [January 18, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/nginx-reverse-proxy-with-ip-based-vhosts-apache/126448/3 "2008-01-18T23:59:37Z")

</div>

I want to use IP-based virtual hosting (not name based with  
NameVirtualHost)  
for purposes of SSL

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [January 20, 2008, 8:23am UTC](https://www.ruby-forum.com/t/nginx-reverse-proxy-with-ip-based-vhosts-apache/126448/4 "2008-01-20T08:23:27Z")

</div>

“Jamie Q.” wrote:

> If I use apache’s name based virtual hosts everything works out great,  
> however if I use IP based virtual hosts, apache does not direct to  
> the right virtual host, instead just defaulting to the main Document  
> Root. I can’t seem to find an answer on Google anywhere, so any  
> feedback is greatly appreciated (relevant part of nginx.conf below).

Hi,  
for name based virtual hosts, a web server uses the request Host header  
to decide which virtual host to dispatch to.  
When you use IP based virtual hosts, you need to set them up to listen  
on different ports and/or ip addresses. If you don’t, apache has no way  
of knowing which virtual host is the right one, just like you describe.

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [January 21, 2008, 1:13am UTC](https://www.ruby-forum.com/t/nginx-reverse-proxy-with-ip-based-vhosts-apache/126448/5 "2008-01-21T01:13:33Z")

</div>

I am aware of this, however the problem I am having is that apache can  
not  
differentiate because it sees everything coming from nginx as  
127.0.0.1(localhost). Thus the only way it works is if I do the  
following…  
\<VirtualHost 127.0.0.1:8080\>  
…

When in reality I want something like this…

\<VirtualHost 77.77.66.66:8080\>  
…

\<VirtualHost 77.77.66.65:8080\>  
…

\<VirtualHost 77.77.66.64:8080\>  
…

Which I cannot do without having some way to get the IP from behind  
nginx.

~Jamie
