0
0
Nginxdevops~30 mins

Blue-green deployment routing in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Blue-green deployment routing with Nginx
📖 Scenario: You are managing a web service that needs zero downtime during updates. To do this, you use a blue-green deployment strategy. This means you have two versions of your app running: blue and green. You want to configure Nginx to route all user traffic to only one version at a time.
🎯 Goal: Build an Nginx configuration that routes all incoming requests to either the blue or green backend server based on a variable. This will let you switch traffic between versions easily.
📋 What You'll Learn
Create an upstream block for blue servers
Create an upstream block for green servers
Add a variable $active_version to select which upstream to use
Configure the server block to proxy requests to the selected upstream
Print the active version in the response header for verification
💡 Why This Matters
🌍 Real World
Blue-green deployment routing is used in production to update applications without downtime. It allows switching user traffic between two identical environments safely.
💼 Career
Understanding how to configure Nginx for blue-green deployments is valuable for DevOps engineers and site reliability engineers who manage continuous delivery pipelines and high-availability services.
Progress0 / 4 steps
1
Create upstream blocks for blue and green servers
Create two upstream blocks named blue_backend and green_backend. Each should have one server: blue.example.com:8080 for blue and green.example.com:8080 for green.
Nginx
Need a hint?

Use the upstream directive to define backend groups.

2
Add a variable to select the active backend
Add a variable $active_version and set it to blue_backend to start routing traffic to the blue version.
Nginx
Need a hint?

Use the map directive to set $active_version to blue_backend by default.

3
Configure server block to proxy to the active backend
Create a server block listening on port 80. Inside it, add a location / block that proxies requests to the backend selected by $active_version using proxy_pass http://$active_version;. Also add a header X-Active-Version with the value of $active_version.
Nginx
Need a hint?

Use proxy_pass with the variable $active_version to route traffic dynamically.

4
Print the active version header for verification
Add a line to print the value of the X-Active-Version header in the response. Then reload Nginx and test by sending a request to port 80. The output should include the header X-Active-Version: blue_backend.
Nginx
Need a hint?

Use curl -I http://localhost to see response headers including X-Active-Version.