Question

Load Balancing(NGINX) Help Needed.

Posted October 6, 2013 7.3k views
Hi, I am working on Load Balancing for my websites... I got this: upstream backend { ny1 192.241.143.207; ny2 162.243.27.154; sf1 162.243.133.133; } The servers host like 7 sites each(all the same files)... What do I put in here: ny1 { location / { proxy_pass http://backend;

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
17 answers
Your config looks proper except that
ny1 { 

location / {
proxy_pass http://backend; }
}
should perhaps be
server { 

location / {
proxy_set_header Host $host;
proxy_pass http://backend;
}
}
instead.
Hey Kamal!
What would I put for proxy_pass though? Why is http://backend in the tutorial? o.O
proxy_pass http://backend instructs nginx to proxy to the upstream that is called backend which you have defined in the first 5 lines.

It should also be
upstream backend { 

server 192.241.143.207;
server 162.243.27.154;
server 162.243.133.133;
}
instead of
upstream backend { 

ny1 192.241.143.207;
ny2 162.243.27.154;
sf1 162.243.133.133;
}
OH! Thanks. I will let you know how it goes.
I gave you a twitter shout out :)
I'm getting this:
root@load-balancer:~# service nginx reload
Reloading nginx configuration: nginx: [emerg] unknown directive "ny1" in /etc/nginx/sites-enabled/default:2
nginx: configuration file /etc/nginx/nginx.conf test failed
With this:
upstream backend {
ny1 192.241.143.207;
ny2 162.243.27.154;
sf1 162.243.133.133;
}

ny1 {
location / {
proxy_set_header Host $host;
proxy_pass http://backend;
}
}

ny2 {
location / {
proxy_set_header Host $host;
proxy_pass http://backend;
}
}

sf1 {
location / {
proxy_set_header Host $host;
proxy_pass http://backend;
}
}
Do I need anything else other than that in my "default" file? It's all I got.
Oh wait! I'll take a gamble that ny1,ny2,sf1 needs to be server as in the tutorial. I thought it was placeholder.
You don't need all of these server blocks. You need only one upstream block and server block.
Nope:
upstream backend {
ny1 192.241.143.207;
ny2 162.243.27.154;
sf1 162.243.133.133;
}

server {
location / {
proxy_set_header Host $host;
proxy_pass http://backend;
}
}

You able to correct me? :/
New to NGINX kinda. :D I like experimenting.
Try this config instead: https://p.kk7.me/geruxucohu.nginx

Also, it's worth mentioning that this config should be on a separate nginx load balancer so you will have 4 servers in total.
I have 4 servers in total. And I sussed it out!
upstream backend {
server 192.241.143.207;
server 162.243.27.154;
server 162.243.133.133;
}

server {
location / {
proxy_set_header Host $host;
proxy_pass http://backend;
}
}
Previous 1 2 Next