0
0
Nginxdevops~10 mins

Blue-green deployment routing in Nginx - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Blue-green deployment routing
Start with Blue environment live
Deploy new version to Green environment
Switch router from Blue to Green
Green environment serves all traffic
Keep Blue as backup or update it
Repeat cycle for next deployment
Traffic is routed to one environment (Blue or Green) at a time. New version deploys to inactive environment, then router switches traffic to it.
Execution Sample
Nginx
server {
  listen 80;
  location / {
    proxy_pass http://blue_backend;
  }
}

# Switch proxy_pass to http://green_backend to route traffic
Nginx routes incoming requests to the active backend (blue or green). Switching proxy_pass changes live environment.
Process Table
StepCurrent Active BackendActionRouting ChangeResult
1blue_backendInitial stateproxy_pass http://blue_backend;All traffic goes to Blue
2blue_backendDeploy new version to GreenNo routing changeGreen environment ready but inactive
3green_backendSwitch proxy_pass to Greenproxy_pass http://green_backend;All traffic now goes to Green
4green_backendBlue kept as backupNo routing changeBlue environment idle, ready for rollback
5green_backendNext deployment prepares BlueNo routing changeBlue updated, inactive
6blue_backendSwitch proxy_pass back to Blueproxy_pass http://blue_backend;Traffic switches back to Blue
💡 Traffic routing switches only after new environment is ready, ensuring zero downtime.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 6
active_backendblue_backendblue_backendgreen_backendgreen_backendblue_backend
blue_statuslivelivebackupbackuplive
green_statusidlereadyliveliveidle
Key Moments - 3 Insights
Why does traffic not switch immediately when deploying the new version?
Traffic switches only after the new environment (Green) is fully ready, as shown in step 2 and 3 of the execution_table, to avoid downtime.
What happens to the old environment after switching traffic?
The old environment (Blue) becomes backup or idle, ready for rollback or next update, as shown in step 4 of the execution_table.
How does nginx know which environment to send traffic to?
Nginx uses the proxy_pass directive to route traffic to either blue_backend or green_backend, changed manually or by automation as shown in the code sample.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the active backend after switching?
Agreen_backend
Bblue_backend
Cboth blue and green
Dnone
💡 Hint
Check the 'Current Active Backend' column at step 3 in the execution_table.
At which step does the green environment become ready but not yet active?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look for when the green environment status changes to 'ready' in variable_tracker and execution_table.
If proxy_pass is not switched after deployment, what happens to traffic?
ATraffic stops
BTraffic is split evenly
CTraffic continues to go to old environment
DTraffic goes to both environments
💡 Hint
Refer to execution_table step 2 where deployment happens but routing does not change.
Concept Snapshot
Blue-green deployment uses two environments: Blue (live) and Green (new).
Deploy new version to inactive environment.
Switch router (nginx proxy_pass) to new environment after ready.
Old environment kept as backup for rollback.
Ensures zero downtime and safe updates.
Full Transcript
Blue-green deployment routing means having two environments: one live (Blue) and one idle (Green). You deploy the new version to the idle environment first. Once it is ready, you switch the router, like nginx's proxy_pass, to send all traffic to the new environment. The old environment stays as backup. This way, users experience no downtime during updates. The execution table shows each step: starting with Blue live, deploying Green, switching traffic, and keeping Blue as backup. Variables track which backend is active and their statuses. Key moments clarify why traffic switches only after readiness and how nginx routes traffic. The quiz tests understanding of active backend and routing changes. The snapshot summarizes the process simply and clearly.