How to use nginx as loadbalancer for different webserver?

Hello all.

I’m new to this maillinglist as to nginx as well. I setup a nginx to run
as
a loadbalancer with just adding the following lines to my
/etc/nginx/nginx_conf. This config works fine.

http {
upstream loadbalancer1 {
server 192.168.0.1:80;
server 192.168.0.2:80;
}

server {
listen 80;
server_name www.example.com example.com;
location / {
proxy_pass http://loadbalancer1;
}
}

Please note, that example.com isn’t my real domain. So that’s not the
error. :wink:

Now I tried to add a second site which is hosted on two different
webservers. My configuration in /etc/nginx/nginx_conf looks like the
following now.

http {
upstream loadbalancer1 {
server 192.168.0.1:80;
server 192.168.0.2:80;
}

server {
listen 80;
server_name www.example.com example.com;
location / {
proxy_pass http://loadbalancer1;
}
}

upstream loadbalancer2 {
server 192.168.0.3:80;
server 192.168.0.4:80;
}

server {
listen 80;
server_name www.anyway.com anyway.com;
location / {
proxy_pass http://loadbalancer2;
}
}}

But if I try to get www.anyway.com it didn’t work and I got a request
timeout. Could somebody please tell me, what’s wrong with my
configuration?

Best Regards

Joerg

Try telnetting to port 80 on 192.168.0.3 and .4 to check they’re
listening, and that www.anyway.com resolves correctly…

On Sun, 2013-04-21 at 08:29 +0200, Jörg Kastning wrote:

server 192.168.0.2:80;

Please note, that example.com isn’t my real domain. So that’s not the error. :wink:
server 192.168.0.2:80;
upstream loadbalancer2 {
}


nginx mailing list
[email protected]
nginx Info Page


Steve H. BSc(Hons) MIITP

Skype: sholdowa

can you make sure that anyway.com ist reachable?

sounds like the path to your front-lb is somehow
not working.

i think i dont need to ask for an nginx-restart after config-changes?

if you upstream-config is messy or your upstream-servers
are unreachable you should usually see a:
502 Bad Gateway

regards,

mex

Posted at Nginx Forum:

Hi.

I found the mistake. The Firewall-Policy was configured but the used
Host-Object was wrong. There were the wrong ip addresses for my
webservrs
added. I changed this and can reach my webservers now.

Thanks for your help.

Mit freundlichen Gren

Jrg Kastning
IT-Systemadministrator

SYNAXON AG
Falkenstrae 31
33758 Schlo Holte-Stukenbrock
Fon: +49(0)5207 9299-282
Fax +49(0)5207 9299-296
mailto: [email protected]
XMPP: [email protected]

Vorstand: Frank Roebers (Vorsitzender), Andreas Wenninger, Mark Schrder
Aufsichtsratsvorsitzender: Dr. Gnter Lewald
Handelsregister Bielefeld HRB 36014

Weitere Infos unter: http://www.synaxon.de

2013/4/21 mex [email protected]