I have nginx as a LB. And the 2 Apaches as the web servers. Lets say i got different domains:
- www.example.com
- checkout.example.com
Both domains will be in same 2 Apache Servers. But ofcoz under the different directories. And with the different VHost
files on the Apache vhost file.
As something like below design:
Nginx
|
-------------
| |
Apache Apache
Below is my current existing Nginx .conf file which is not working for the second Domain (checkout.example.com).
From NGINX (mysites.conf):
upstream serverpool {
server 1.2.3.101:80 weight=1;
server 1.2.3.102:80 weight=1;
}
server {
listen 80;
server_name www.example.com checkout.example.com;
location / {
proxy_pass http://serverpool;
}
}
From both of 2 Apache Servers' same Vhost Files (httpd.conf):
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html/www.example.com/
</VirtualHost>
<VirtualHost *:80>
ServerName checkout.example.com
DocumentRoot /var/www/html/checkout.example.com/
</VirtualHost>
But whenever i browse that (http://checkout.example.com), the Domain still comes up in browser .. but with the contents of (www.example.com), which is totally wrong.
What did i do wrong please?
You should almost always set
Host
header. Otherwise nginx falls back to defaultproxy_set_header Host $proxy_host;
which in your case would beserverpool
which is useless for apache.See http://nginx.org/r/proxy_set_header and http://nginx.org/r/proxy_pass for details.
you will need to send HOST: header to your upstream server IP's also
this artical is fully ansering to question
Make nginx to pass hostname of the upstream when reverseproxying
also you nginx config should looks like this