# Distinct upstream servers by name

**URL:** <https://www.ruby-forum.com/t/distinct-upstream-servers-by-name/201688>\
**Category:** NGINX\
**Created:** [January 12, 2011, 10:27pm UTC](https://www.ruby-forum.com/t/distinct-upstream-servers-by-name/201688 "2011-01-12T22:27:49Z")\
**Posts on this page:** 2\
**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:** [January 12, 2011, 10:27pm UTC](https://www.ruby-forum.com/t/distinct-upstream-servers-by-name/201688/1 "2011-01-12T22:27:49Z")

</div>

Hello.

I want to proxy 2 apache vhosts.  
Both vhosts running on apache default port: 8080 and both are resolved  
through /etc/hosts

upstream ultimabex\_upstream{  
server ultimabex.va:8080;  
server ultimabex.vb:8080;  
}

The issue is how to send correct Host header to apache so it will find  
vhost in his vhosts.conf  
and serve it accordingly.

Used custom LogFormat in apache to catch ServerName(%v),  
Canonical ServerName(%V) ans Host(%h) headers sent by nginx.  
Setting Host in nginx is altering Canonical ServerName(%V) in apache  
headers.

tried:  
proxy\_set\_header Host $upstream\_http\_host - resulting in 127.0.0.1 in  
apache logs  
proxy\_set\_header Host $upstream\_http\_hostname - resulting in first  
found apache vhost

It works great when i set Host manually, like:  
proxy\_set\_header Host “ultimabex.va”  
or  
proxy\_set\_header Host “ultimabex.vb”

Any way to set it automatically?

Thank you.

Posted at Nginx Forum:

> **[Distinct upstream servers by name](https://forum.nginx.org/read.php?2,165716,165716#msg-165716)**
>
> Hello. I want to proxy 2 apache vhosts. Both vhosts running on apache default port: 8080 and both are resolved through /etc/hosts upstream ultimabex\_upstream{ server ultimabex.va:8080; server ultimabex.vb:8080; } The issue

---

<div class="post-metadata">

**Author:** ![hydrow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7993a0/32.png) [@hydrow](https://www.ruby-forum.com/u/hydrow)\
**Post date:** [January 13, 2011, 2:49pm UTC](https://www.ruby-forum.com/t/distinct-upstream-servers-by-name/201688/2 "2011-01-13T14:49:45Z")

</div>

Hello!

On Wed, Jan 12, 2011 at 04:26:54PM -0500, hydrow wrote:

> proxy\_set\_header Host $upstream\_http\_host - resulting in 127.0.0.1 in  
> apache logs  
> proxy\_set\_header Host $upstream\_http\_hostname - resulting in first  
> found apache vhost
> 
> It works great when i set Host manually, like:  
> proxy\_set\_header Host “ultimabex.va”  
> or  
> proxy\_set\_header Host “ultimabex.vb”
> 
> Any way to set it automatically?

No. The same upstream request is used to communicate with all  
backend servers (including fallback via proxy\_next\_upstream to  
another server if one backends dies), so the Host header can’t be  
different for different backend servers.

You have to configure identical ServerName’s on all backends (or  
add ServerAlias) and use that name in proxy\_set\_header.

Maxim D.
