NGINX与“serverpool”作为不同的域在相同的Apache服务器的LB?

我有nginx作为LB. 而2阿帕奇作为networking服务器。 比方说,我有不同的领

  • www.example.com
  • checkout.example.com

两个域将在同一个Apache服务器上。 但是在不同的目录下。 以及Apache vhost文件上的不同VHost文件。

像下面这样的devise:

  Nginx | ------------- | | Apache Apache 

下面是我现有的Nginx .conf文件,它不适用于第二个域(checkout.example.com)。

来自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; } } 

从两个Apache服务器的相同的 Vhost文件(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> 

但是,无论何时我浏览( http://checkout.example.com ), 域仍然在浏览器中, 但与(www.example.com)的内容 ,这是完全错误的。

请问我做错了什么?

你应该几乎总是设置Host头。 否则,nginx会回到默认值proxy_set_header Host $proxy_host; 在你的情况下,这将是服务器serverpool ,这是无用的阿帕奇。

有关详细信息,请参阅http://nginx.org/r/proxy_set_header和http://nginx.org/r/proxy_pass

 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; proxy_set_header Host $host; } } 

您将需要发送HOST:头到您的上游服务器IP也

这个艺术是完全不容置疑的

使nginx在反向模式下传递上游的主机名

另外你的nginxconfiguration应该看起来像这样

  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; proxy_set_header Host $host; } }