Skip to content

ilmsg/nginx-load-balance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nginx-load-balance

nginx ทำ load balance ด้วย round robin

load balancing algorithms

  1. round robin
  2. sticky round robin
  3. least time
  4. least connections
  5. ip/url hash
  6. weighted round robin

run docker compose

$ docker compose up -d --build

website: http://webapp.local:3000/

เรารัน webapp ไว้ 3 ตัว แต่ละตัวจะใส่ env ที่เป็น KEY เอาไว้เป็น key1, key2, key3 เพื่อให้รู้ว่าหน้าเว็บที่รันขึ้นมา ถูกเรียกจาก webapp ตัวไหน

เรากด refresh หน้าเว็บไปเรื่อยๆ จะเห็นว่าค่า key จะหมุนเปลี่ยนไปเรื่อยๆ key1 -> key2 -> key3 -> key1 .... หมุนวน แบบนี้ไปเรื่อยๆ

ถ้าเราลอง down webapp2 ลงไป หน้าเว็บก็จะออกแค่ key1 กับ key3 หมุนวนไป

https://github.com/ilmsg/nginx-load-balance/blob/main/images/2023-12-29_130616.png?raw=true

https://github.com/ilmsg/nginx-load-balance/blob/main/images/2023-12-29_130629.png?raw=true

https://github.com/ilmsg/nginx-load-balance/blob/main/images/2023-12-29_130638.png?raw=true

note: ตอนแรกจะทำ sticky round robin แต่พบว่า ต้องใช้ nginx ที่เป็น version nginx (>=1.5.7) ขึ้นไป ซึ่งนั้นจะเป็นแบบ commercial subscription http://nginx.org/en/docs/http/ngx_http_upstream_module.html#sticky

About

nginx ทำ load balance ด้วย round robin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published