test servers:
echp 'PHP Server 1'> s1
echp 'PHP Server 2'> s2
echp 'PHP Server 3'> s3
php -S localhost:10001 s1
php -S localhost:10002 s2
php -S localhost:10003 s3
curl http://localhost:10001
curl http://localhost:10002
curl http://localhost:10003
load-balancer.conf
----
events{}
http{
server{
listen 8888;
location / {
proxy_pass 'http://localhost:10001/';
}
}
}
------
nginx -c /<path>/load-balancer.conf
curl http://localhost:8888
while sleep 0.5;do curl http://localhost:8888; done
-------
load-balancer.conf
----
events{}
http{
upstream php_servers{
server localhost:10001;
server localhost:10002;
server localhost:10003;
}
server{
listen 8888;
location / {
proxy_pass http://php_servers;
}
}
}
---
default behavior is round robin---to send next request to next server in upstream
sticky sessions ---request is bound to users ip hash and routes to same server for the session
load-balancer.conf
----
events{}
http{
upstream php_servers{
ip_hash;
server localhost:10001;
server localhost:10002;
server localhost:10003;
}
server{
listen 8888;
location / {
proxy_pass http://php_servers;
}
}
}
distribute requests based on load and pass them to server with least number of active connections
upstream php_servers{
least_conn; //ip_hash;
---
---
}
No comments:
Post a Comment