0
0
Nginxdevops~10 mins

Backup servers in Nginx - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Backup servers
Client sends request
Primary server receives request
Is primary server UP?
NoSend request to backup server
|Yes
Primary server processes request
Response sent to client
The client sends a request to the primary server. If the primary server is down, the request is sent to the backup server instead.
Execution Sample
Nginx
upstream backend {
    server primary.example.com;
    server backup.example.com backup;
}

server {
    location / { proxy_pass http://backend; }
}
This nginx config defines a primary and a backup server. Requests go to primary unless it is down, then to backup.
Process Table
StepEventPrimary Server StatusAction TakenResponse Source
1Client sends requestUPSend to primary serverprimary.example.com
2Primary server respondsUPServe responseprimary.example.com
3Client sends requestDOWNSend to backup serverbackup.example.com
4Backup server respondsDOWNServe responsebackup.example.com
5Client sends requestUPSend to primary serverprimary.example.com
💡 Requests stop or continue depending on server availability; backup used only if primary is down.
Status Tracker
VariableStartAfter 1After 2After 3After 4After 5
Primary Server StatusUPUPUPDOWNDOWNUP
Request Routed Toprimary.example.comprimary.example.comprimary.example.combackup.example.combackup.example.comprimary.example.com
Response Sourceprimary.example.comprimary.example.comprimary.example.combackup.example.combackup.example.comprimary.example.com
Key Moments - 2 Insights
Why does nginx send requests to the backup server only when the primary is down?
Because the backup server is marked with the 'backup' keyword, nginx uses it only if the primary server is unavailable, as shown in execution_table rows 3 and 4.
What happens if the primary server comes back up after being down?
Nginx automatically routes requests back to the primary server once it is detected as UP again, as seen in execution_table row 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at step 3, which server receives the client request?
Aprimary.example.com
Bbackup.example.com
CBoth servers
DNo server
💡 Hint
Check the 'Action Taken' and 'Response Source' columns at step 3.
At which step does nginx switch back to the primary server after downtime?
AStep 5
BStep 3
CStep 2
DStep 4
💡 Hint
Look for when 'Primary Server Status' changes back to UP and 'Request Routed To' is primary.
If the backup server was not marked as 'backup' in the config, what would happen?
ANginx would never use the backup server
BNginx would only use the backup server
CNginx would load balance between both servers always
DNginx would fail to start
💡 Hint
Consider how nginx treats servers without the 'backup' keyword in upstream blocks.
Concept Snapshot
nginx backup servers:
- Define upstream with primary and backup servers
- Use 'backup' keyword for fallback server
- Requests go to primary if UP
- If primary DOWN, requests go to backup
- Automatic failover and recovery
Full Transcript
This visual execution shows how nginx handles backup servers. The client sends requests to the primary server first. If the primary server is up, nginx routes requests there and serves responses from it. If the primary server goes down, nginx automatically sends requests to the backup server marked with the 'backup' keyword. When the primary server recovers, nginx switches back to it. The execution table tracks each step, showing server status, routing decisions, and response sources. This setup ensures high availability by providing a fallback server without manual intervention.