# Upstream server does not match virtual host

**URL:** <https://www.ruby-forum.com/t/upstream-server-does-not-match-virtual-host/244289>\
**Category:** NGINX\
**Created:** [March 16, 2016, 1:21am UTC](https://www.ruby-forum.com/t/upstream-server-does-not-match-virtual-host/244289 "2016-03-16T01:21:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [March 16, 2016, 1:21am UTC](https://www.ruby-forum.com/t/upstream-server-does-not-match-virtual-host/244289/1 "2016-03-16T01:21:07Z")

</div>

Hello,

I have a web server (nginx, iis, apache, whatever) on which I access:  
[http://1.1.1.1](http://1.1.1.1) =\> displays default page  
[http://virt1](http://virt1) =\> displays virtual host 1 (ping virt 1 = 1.1.1.1)  
When I access the url virt1 the page of the corresponding virtual host  
which  
is different from when I access the url with the ip adress  
NB: if I access [http://1.1.1.1/virt1](http://1.1.1.1/virt1), it’s the same page as [http://virt1](http://virt1)

I use a nginx server in front of it as a reverse proxy and use a virtual  
host. When I access [http://portal](http://portal), I want it to display the page as if  
it  
was [http://virt1](http://virt1)

My configuration starts like this  
upstream webservers { server virt1:80; }  
server {  
listen 80;  
server\_name server\_name portal;  
index index.php index.html;  
location @proxy {  
proxy\_pass [http://webservers](http://webservers);  
include /etc/nginx/proxy\_params;  
}

With this configuration it works but not as I wish.  
When I access the page [http://portal](http://portal) it displays the page as if I  
accessed  
[http://1.1.1.1](http://1.1.1.1) but I wanted it to display the page that looks like  
[http://virt1](http://virt1)  
If I access [http://portal/virt1](http://portal/virt1) it displays the correct page.

Conclusion my configuration makes my nginx connect to the right server  
but  
doesn’t send a parameter so that I access on the right virtual host.

Do you know how to correct this ?

Thank you

Posted at Nginx Forum:

> **[upstream server does not match virtual host](https://forum.nginx.org/read.php?2,265370,265370#msg-265370)**
>
> Hello, I have a web server (nginx, iis, apache, whatever) on which I access: http://1.1.1.1 =\> displays default page http://virt1 =\> displays virtual host 1 (ping virt 1 = 1.1.1.1) When I access the url virt1 the page of the corresponding...

---

<div class="post-metadata">

**Author:** ![miky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@miky](https://www.ruby-forum.com/u/miky)\
**Post date:** [March 16, 2016, 9:34am UTC](https://www.ruby-forum.com/t/upstream-server-does-not-match-virtual-host/244289/2 "2016-03-16T09:34:44Z")

</div>

On Tue, Mar 15, 2016 at 08:20:25PM -0400, miky wrote:

Hi there,

> I use a nginx server in front of it as a reverse proxy and use a virtual  
> host. When I access [http://portal](http://portal), I want it to display the page as if it  
> was [http://virt1](http://virt1)

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![miky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@miky](https://www.ruby-forum.com/u/miky)\
**Post date:** [March 16, 2016, 12:34pm UTC](https://www.ruby-forum.com/t/upstream-server-does-not-match-virtual-host/244289/3 "2016-03-16T12:34:05Z")

</div>

Thank you Francis for pointing the right direction.

If I understand correctly the documentation I should add  
proxy\_set\_header Host $host;

considering I had the upstream server defined by: upstream webservers {  
server virt1:80; }

I tried it but had no luck with it, I also tried $http\_host; and  
$proxy\_host;

Also should I place this proxy\_set\_header before the proxy\_pass ? I  
think  
yes, could you confirm this ?

Regards

Posted at Nginx Forum:

> **[Re: upstream server does not match virtual host](https://forum.nginx.org/read.php?2,265370,265391#msg-265391)**
>
> Hello, I have a web server (nginx, iis, apache, whatever) on which I access: http://1.1.1.1 =\> displays default page http://virt1 =\> displays virtual host 1 (ping virt 1 = 1.1.1.1) When I access the url virt1 the page of the corresponding...

---

<div class="post-metadata">

**Author:** ![miky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@miky](https://www.ruby-forum.com/u/miky)\
**Post date:** [March 17, 2016, 12:12am UTC](https://www.ruby-forum.com/t/upstream-server-does-not-match-virtual-host/244289/4 "2016-03-17T00:12:46Z")

</div>

Francis,

Thank you very much, your help is always appreciated.

It didn’t work in the first place because I also had an include proxy  
params  
statement which overrided the setting you indicated.

Retesting from a very basic configuration proved the solution you  
offered  
worked.

At the end I kept the include proxy param and modified what I wanted  
there.

Have a nice day

Posted at Nginx Forum:

> **[Re: upstream server does not match virtual host - SOLVED](https://forum.nginx.org/read.php?2,265370,265417#msg-265417)**
>
> Hello, I have a web server (nginx, iis, apache, whatever) on which I access: http://1.1.1.1 =\> displays default page http://virt1 =\> displays virtual host 1 (ping virt 1 = 1.1.1.1) When I access the url virt1 the page of the corresponding...

---

<div class="post-metadata">

**Author:** ![miky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@miky](https://www.ruby-forum.com/u/miky)\
**Post date:** [March 16, 2016, 5:53pm UTC](https://www.ruby-forum.com/t/upstream-server-does-not-match-virtual-host/244289/5 "2016-03-16T17:53:03Z")

</div>

On Wed, Mar 16, 2016 at 07:33:45AM -0400, miky wrote:

Hi there,

> If I understand correctly the documentation I should add  
> proxy\_set\_header Host $host;

What Host: header is sent by the browser to the upstream web server when  
things work?

From the original mail, that seems to be “virt1”.

So you want

proxy\_set\_header Host virt1;

> Also should I place this proxy\_set\_header before the proxy\_pass ? I think  
> yes, could you confirm this ?

Easiest is to say “in the same {}-block as the proxy\_pass”.

The order of the two within that block does not matter.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
