>_ IzzyLab

Hands-on task

This task is step 17 of the course “nginx basics”

Load balancing two backends

medium~12 min

Two instances of the app are already running: 127.0.0.1:5001 and 127.0.0.1:5002. Configure nginx on port 80 to balance between them — repeated requests to http://localhost/ should reach both backends.

What you'll practise:
  • nginx
  • upstream
  • proxy_pass
  • load balancing
  • round-robin

Topic breakdown

Load balancing distributes incoming requests across several identical backends. In nginx it's a combo of a named group of servers (the upstream block) and the proxy_pass directive, which forwards requests to that group; by default the spread goes in a circle (round-robin). It's critical that the group name matches in the declaration and in proxy_pass, and that all backends are listed inside the group — otherwise traffic will only go to some of them.

What's checked

  1. backend-one responds through port 80
  2. backend-two responds through port 80

What it looks like