# Proxy, upstream, apache vhosts not working

**URL:** <https://www.ruby-forum.com/t/proxy-upstream-apache-vhosts-not-working/221697>\
**Category:** NGINX\
**Created:** [July 26, 2012, 4:49pm UTC](https://www.ruby-forum.com/t/proxy-upstream-apache-vhosts-not-working/221697 "2012-07-26T16:49:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [July 26, 2012, 4:49pm UTC](https://www.ruby-forum.com/t/proxy-upstream-apache-vhosts-not-working/221697/1 "2012-07-26T16:49:21Z")

</div>

Hi,

I want to configure nginx as a proxy to a bunch of apaches, all serving  
the same multiple websites via vhosts.

I had it working with something like  
location ~\* .(jpg|gif|png|css|js) {  
try\_files $uri @proxy;  
}  
location @proxy {  
proxy\_pass [http://www.acme.net](http://www.acme.net);  
}  
location / {  
proxy\_pass [http://www.acme.net](http://www.acme.net);  
}

in my server section.  
But this only asked a single apache, the one configured in /etc/hosts  
for [http://www.acme.net](http://www.acme.net).

Now I am trying to use all of my apaches. I defined an upstream block  
like this:  
upstream backend-all-apaches {  
server 10.10.1.25;  
server 10.10.1.26;  
server 10.10.1.27;  
server 10.10.1.28;  
server 10.10.1.15;  
server 10.10.1.18;  
server 10.10.1.20;  
}  
proxy\_set\_header Host $host;

And the following in my server block:  
location @proxy {  
proxy\_pass [http://backend-all-apaches](http://backend-all-apaches);  
}  
All I get in my browser is a default page that also gets deliverd when I  
call [http://10.10.1.25](http://10.10.1.25) in my browser. So I assume the apaches don’t get  
the right host value in the http header. I thought that  
proxy\_set\_header Host $host;  
would solve this problem, but apprently it does not.

What am I doing wrong here, or what else could I try?

Isaac

---

<div class="post-metadata">

**Author:** ![Isaac\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e480ec/32.png) [@Isaac\_H](https://www.ruby-forum.com/u/Isaac_H)\
**Post date:** [July 26, 2012, 5:43pm UTC](https://www.ruby-forum.com/t/proxy-upstream-apache-vhosts-not-working/221697/2 "2012-07-26T17:43:06Z")

</div>

On Thursday 26 July 2012 18:48:45 Isaac H. wrote:

> ```
> proxy_pass http://www.acme.net;
> 
> ```
> 
> like this:
> 
> What am I doing wrong here, or what else could I try?

Is the above configuration is exactly what you’re actually use?

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Isaac\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e480ec/32.png) [@Isaac\_H](https://www.ruby-forum.com/u/Isaac_H)\
**Post date:** [July 27, 2012, 10:46am UTC](https://www.ruby-forum.com/t/proxy-upstream-apache-vhosts-not-working/221697/3 "2012-07-27T10:46:27Z")

</div>

On 07/26/2012 05:42 PM, Valentin V. Bartenev wrote:

> > ```
> > location @proxy {
> > 
> > ```
> > 
> > Now I am trying to use all of my apaches. I defined an upstream block  
> > proxy\_set\_header Host $host;
> > 
> > What am I doing wrong here, or what else could I try?
> 
> Is the above configuration is exactly what you’re actually use?  
> Almost. I changed IPs and servername, the rest is the same.

Isaac

---

<div class="post-metadata">

**Author:** ![Isaac\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e480ec/32.png) [@Isaac\_H](https://www.ruby-forum.com/u/Isaac_H)\
**Post date:** [July 27, 2012, 11:16am UTC](https://www.ruby-forum.com/t/proxy-upstream-apache-vhosts-not-working/221697/4 "2012-07-27T11:16:14Z")

</div>

So I finally found the reason: the nginx cache bit me 🙂  
First I did not have the line  
proxy\_set\_header Host $host;  
which got me that default page into my cache. Any subsequent  
calls pulled that default page, since nginx does not know that  
its just a default page I guess. So any changes I made to the config did  
not change the cache. Once I removed the cache, the config line  
stated above did the trick.

I noticed this because when I came back to work this morning it  
suddently was working. So I tried to change the config and see what  
it was, and was stuck again with the default page.  
I then started tcpdump to see what the header would look like that got  
send to apache. I realized that nothing got send to apache, which lead  
me to the conclusion that nginx was serving out of cache. Removing  
the cache did the trick.

Sorry for bothering you.

Isaac
