Opened 7 years ago

Closed 7 years ago

Last modified 2 years ago

#313 closed defect (invalid)

Issue with load balance several Apache instances.

Reported by: www.google.com/accounts/o8/id?id=AItOawkmsDH7CdQVS_pGSV4jKL_D0xD7q6tdT7w Owned by:
Priority: major Milestone:
Component: nginx-core Version: 1.1.x
Keywords: load balancing Cc: chamith.malinda@…
uname -a: Linux chamith-HP-Pavilion-g6-Notebook-PC 3.2.0-24-generic-pae #39-Ubuntu SMP Mon May 21 18:54:21 UTC 2012 i686 i686 i386 GNU/Linux
nginx -V: TLS SNI support enabled configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-dav-ext-module

Description

Hi,

I tried to load balance two Apache instances (virtual hosts) In two different physical servers.
Each one having more than one Apache virtual hosts with different domain names.

Let say there are two physical servers called "A" and "B",

Physical machine "A" have Apache virtual hosts with following domain names.

  1. exampleA1.com
  2. exampleA2.com

etc . . .

Physical machine "B" have Apache virtual hosts with following domain names.

  1. exampleB1.com
  2. exampleB2.com

etc . . .

Those Apache virtual hosts are working fine.

And I need to load balance exampleA1.com and exampleB1.com. So I used nginx for this with following configuration in my Local PC (for test before putting to a live server)

My target is load balance exampleA1.com and exampleB1.com from my local PC.

Following is my nginx.conf modifications,

http {

upstream localhost {

server exampleA1.com:80;
server exampleB1.com:80;

}

server {

listen localhost:80;
server_name localhost;

location / {
proxy_pass http://localhost;
}
}

}

So then when accessing http://localhost load balancing need to be happen.
And yes It's happening. But one problem.

It's picking other virtual host (Domain name) in the "A" physical machine. Instead of "exampleA1.com" it's picking "exampleA2.com" or any other one. In the "B" machine the same problem.

(When use browser to access those Apache URL 's - Working fine - directing to the correct destination)

Can't we balance the load two Apache instances in different PC s which are having more than one virtual hosts or Apache instances with different domain names ?


Apache configurations for exampleA1.com and exampleA2.com in "A" server like as follows,

<VirtualHost? *:80>

ServerAdmin? xxxx@…
DocumentRoot? /var/www/
ServerName? exampleA1.com

-----

</VirtualHost?>

<VirtualHost? *:80>

ServerAdmin? xxxx@…
DocumentRoot? /var/www/
ServerName? exampleA2.com

------

</VirtualHost?>

Apache configurations for exampleB1.com and exampleB2.com in "B" server like as follows,

<VirtualHost? *:80>

ServerAdmin? xxxx@…
DocumentRoot? /var/www/
ServerName? exampleB1.com

-----

</VirtualHost?>

<VirtualHost? *:80>

ServerAdmin? xxxx@…
DocumentRoot? /var/www/
ServerName? exampleB2.com

------

</VirtualHost?>

Thanks,
Chamith.

Change History (5)

comment:1 follow-up: Changed 7 years ago by mdounin

  • Resolution set to invalid
  • Status changed from new to closed

Balancing within single upstream block assumes the same request might be routed to any of the servers configured, much like things happen with multiple ip addresses configured for a domain name. Unless overridden with proxy_set_header directive, name you wrote in proxy_pass will be used in a Host header, and you have to configure virtual host "localhost" (== name you wrote in proxy_pass) on both of your backends for things to work.

comment:2 in reply to: ↑ 1 Changed 7 years ago by www.google.com/accounts/o8/id?id=AItOawkmsDH7CdQVS_pGSV4jKL_D0xD7q6tdT7w

Thanks for the explanation.

"you have to configure virtual host "localhost" (== name you wrote in proxy_pass) "

Is this name is "proxy pass" or "server_name" ?

Because If I put proxy_pass ​http://cluster; and put the cluster as the servername of two Virtual hosts in back end It's not working.

http {
upstream cluster {
server exampleA1.com:80;
server exampleB1.com:80;
}
server {
listen localhost:80;
server_name localhost;
location / {
proxy_pass ​http://cluster;
}
}
}

If I put localhost then It's working. Then we have to put the same domain name for two Apache Virtual hosts. Is that correct ?

comment:3 Changed 7 years ago by mdounin

You have to use identical names on two backend's virtual hosts (i.e., in your Apache configs, either using ServerName or ServerAlias directives in Apache configs). And you have to use the same name in nginx's proxy_pass (or, alternatively, use proxy_set_header Host with the name).

comment:4 Changed 7 years ago by www.google.com/accounts/o8/id?id=AItOawkmsDH7CdQVS_pGSV4jKL_D0xD7q6tdT7w

Great Thanks.

comment:5 Changed 2 years ago by mdounin

  • sensitive changed from 1 to 0
Note: See TracTickets for help on using tickets.