0
0
Nginxdevops~30 mins

Canary deployments in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Canary Deployments with Nginx
📖 Scenario: You are working as a DevOps engineer for a web service. Your team wants to test a new version of the website on a small percentage of users before fully releasing it. This is called a canary deployment. You will configure Nginx to route 10% of the traffic to the new version and 90% to the stable version.
🎯 Goal: Build an Nginx configuration that splits incoming user traffic so that 10% goes to the canary backend server and 90% goes to the stable backend server. This helps test new changes safely.
📋 What You'll Learn
Create an upstream block with two backend servers named stable_backend and canary_backend
Add a variable canary_weight set to 10 representing 10% traffic for canary
Use the split_clients directive to split traffic based on $remote_addr into canary and stable
Configure the server block to proxy requests to the correct backend based on the split
Print the final Nginx configuration that routes traffic accordingly
💡 Why This Matters
🌍 Real World
Canary deployments are used in real companies to reduce risk when releasing new software versions by testing changes on a small user group first.
💼 Career
DevOps engineers often configure load balancers like Nginx to manage traffic routing for canary deployments, improving software reliability and user experience.
Progress0 / 4 steps
1
Create upstream backend servers
Create an upstream block named backend with two servers: stable_backend at 192.168.1.10:80 and canary_backend at 192.168.1.20:80.
Nginx
Need a hint?

Use the upstream directive to group backend servers.

2
Add canary traffic weight variable
Add a variable canary_weight and set it to 10 to represent 10% traffic for the canary deployment.
Nginx
Need a hint?

Use the map directive to create a variable based on $remote_addr.

3
Split traffic using split_clients
Use the split_clients directive with $remote_addr to split traffic into canary and stable groups. Assign canary to 10% and stable to 90%.
Nginx
Need a hint?

The split_clients directive helps distribute traffic by percentage.

4
Configure server block to route traffic
Create a server block listening on port 80. Use an if statement to proxy requests to canary_backend if $deployment_group is canary, otherwise proxy to stable_backend. Use proxy_pass with http://backend and the correct server.
Nginx
Need a hint?

Use if inside location to route traffic based on $deployment_group.