Upstream server does not match virtual host

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 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, it’s the same page as 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, I want it to display the page as if
it
was 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;
include /etc/nginx/proxy_params;
}

With this configuration it works but not as I wish.
When I access the page http://portal it displays the page as if I
accessed
http://1.1.1.1 but I wanted it to display the page that looks like
http://virt1
If I access 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:

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, I want it to display the page as if it
was http://virt1

http://nginx.org/r/proxy_set_header

f

Francis D. [email protected]

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:

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:

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. [email protected]