0
0
Nginxdevops~30 mins

Weighted round-robin in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Configure Weighted Round-Robin Load Balancing in Nginx
📖 Scenario: You are setting up a simple load balancer using Nginx to distribute web traffic across multiple backend servers. Some servers are more powerful, so they should receive more traffic. You will configure weighted round-robin to achieve this.
🎯 Goal: Build an Nginx configuration that uses weighted round-robin to balance requests between three backend servers with different weights.
📋 What You'll Learn
Create an upstream block named backend with three servers
Assign weights 3, 2, and 1 to the servers respectively
Configure the server block to proxy requests to the backend upstream
Print the final Nginx configuration to verify the setup
💡 Why This Matters
🌍 Real World
Weighted round-robin helps balance load efficiently when backend servers have different capacities, improving website performance and reliability.
💼 Career
Understanding Nginx load balancing is essential for DevOps roles managing scalable web applications and infrastructure.
Progress0 / 4 steps
1
Create the upstream block with backend servers
Create an upstream block named backend with these three servers exactly: server1.example.com, server2.example.com, and server3.example.com. Do not add weights yet.
Nginx
Need a hint?

Use the upstream directive and list each server inside curly braces.

2
Add weights to the backend servers
Add weights to the servers inside the upstream backend block: assign weight 3 to server1.example.com, weight 2 to server2.example.com, and weight 1 to server3.example.com. Use the syntax server hostname weight=number;.
Nginx
Need a hint?

Add weight= followed by the number after each server hostname.

3
Configure the server block to use the upstream backend
Create a server block that listens on port 80 and proxies all requests to the backend upstream using proxy_pass http://backend; inside the location / block.
Nginx
Need a hint?

Use server block with listen 80; and inside location / use proxy_pass http://backend;.

4
Print the final Nginx configuration
Print the entire Nginx configuration to verify the weighted round-robin setup. Use print() to output the configuration as a string exactly as written.
Nginx
Need a hint?

Use print() with the full configuration string including newlines and indentation.