What if you could update your website without anyone noticing a thing?
Why Blue-green deployment routing in Nginx? - Purpose & Use Cases
Imagine you have a website and want to update it without making visitors see errors or downtime. You try to update the live server directly while people are using it.
Updating the live server manually means users might see broken pages or errors during the update. If something goes wrong, fixing it quickly is hard and stressful.
Blue-green deployment routing lets you run two versions of your site side by side. You switch traffic smoothly from the old version (blue) to the new one (green) using routing rules, so users never see downtime.
stop old server update code start server
set nginx to route traffic to green
monitor green
switch traffic from blue to greenYou can update your website instantly and safely, with zero downtime and easy rollback if needed.
A popular online store uses blue-green routing to release new features without interrupting shoppers, keeping sales smooth and customers happy.
Manual updates cause downtime and risk errors.
Blue-green routing runs two versions side by side.
Switching traffic is fast, safe, and reversible.
Practice
Solution
Step 1: Understand blue-green deployment concept
Blue-green deployment uses two versions of an app (blue and green) to switch traffic smoothly.Step 2: Identify Nginx role in routing
Nginx switches traffic by changingproxy_passbetween blue and green upstreams, avoiding downtime.Final Answer:
To switch traffic between two app versions without downtime -> Option DQuick Check:
Blue-green routing = traffic switch without downtime [OK]
- Confusing blue-green with load balancing
- Thinking it increases server count automatically
- Assuming it handles encryption or caching
Solution
Step 1: Identify directive for routing requests
Theproxy_passdirective tells Nginx where to send incoming requests.Step 2: Understand blue-green switching
Switchingproxy_passbetween blue and green upstream blocks changes the app version served.Final Answer:
proxy_pass -> Option AQuick Check:
proxy_pass switches traffic in blue-green [OK]
- Using listen to switch app versions
- Confusing server_name with routing
- Using root which sets document root, not proxy
upstream blue {
server 10.0.0.1:8080;
}
upstream green {
server 10.0.0.2:8080;
}
server {
listen 80;
location / {
proxy_pass http://green;
}
}Solution
Step 1: Check proxy_pass target
Theproxy_passpoints tohttp://green, so traffic goes to green upstream.Step 2: Identify green upstream server
Green upstream has server10.0.0.2:8080, so this server receives traffic.Final Answer:
10.0.0.2:8080 (green) -> Option BQuick Check:
proxy_pass to green = 10.0.0.2:8080 [OK]
- Assuming traffic goes to blue by default
- Thinking both upstreams get traffic simultaneously
- Believing config has syntax errors
upstream blue {
server 10.0.0.1:8080;
}
upstream green {
server 10.0.0.2:8080
}
server {
listen 80;
location / {
proxy_pass http://blue;
}
}Solution
Step 1: Check upstream block syntax
The green upstream server line lacks a semicolon at the end, causing syntax error.Step 2: Validate other directives
proxy_passwith http is valid; listen can omit IP; upstream names can be lowercase.Final Answer:
Missing semicolon after green server line -> Option AQuick Check:
Missing semicolon causes config error [OK]
- Assuming http must be https in proxy_pass
- Thinking listen needs IP address
- Believing upstream names must be uppercase
Solution
Step 1: Understand zero downtime switch
Changingproxy_passin Nginx config directs traffic to green without downtime.Step 2: Reload Nginx to apply changes
Reloading Nginx applies new config smoothly without dropping connections.Final Answer:
Changeproxy_passin Nginx config from blue to green and reload Nginx -> Option CQuick Check:
proxy_pass switch + reload = zero downtime [OK]
- Stopping blue servers causes downtime
- Relying on DNS changes delays switch
- Restarting Nginx without config change does nothing
Ready to prove it?
Pass the test and this pattern moves unknown
