Bird
Raised Fist0
Nginxdevops~10 mins

Backup servers in Nginx - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Backup servers
Client sends request
↓
Primary server receives request
↓
Is primary server UP?
No→Send 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.

Practice

(1/5)
1. What is the main purpose of marking a server as backup in an upstream block in nginx?
easy
A. To use it only if all main servers are unavailable
B. To prioritize it over main servers for all requests
C. To permanently disable the server
D. To balance load equally with main servers

Solution

  1. Step 1: Understand the role of backup servers

    Backup servers are fallback servers used only when main servers fail.
  2. Step 2: Analyze the backup keyword effect

    Marking a server as backup means it will receive traffic only if main servers are down.
  3. Final Answer:

    To use it only if all main servers are unavailable -> Option A
  4. Quick Check:

    Backup servers = fallback only [OK]
Hint: Backup servers handle traffic only when main servers fail [OK]
Common Mistakes:
  • Thinking backup servers share load equally
  • Assuming backup servers are always active
  • Confusing backup with disabled servers
2. Which of the following is the correct syntax to define a backup server in an nginx upstream block?
easy
A. server 192.168.1.10;
B. server backup 192.168.1.10;
C. server 192.168.1.10 backup;
D. backup server 192.168.1.10;

Solution

  1. Step 1: Recall nginx upstream server syntax

    The correct syntax is server [IP] [parameters]; with parameters like backup after IP.
  2. Step 2: Identify correct placement of backup

    The backup keyword comes after the IP address in the server line.
  3. Final Answer:

    server 192.168.1.10 backup; -> Option C
  4. Quick Check:

    Backup keyword after IP = correct syntax [OK]
Hint: Put 'backup' after IP in server line [OK]
Common Mistakes:
  • Placing 'backup' before IP address
  • Using 'backup server' instead of 'server ... backup;'
  • Omitting semicolon at line end
3. Given this nginx upstream block:
upstream backend {
    server 10.0.0.1;
    server 10.0.0.2 backup;
}

Which server will nginx send requests to if 10.0.0.1 is up?
medium
A. 10.0.0.1 only
B. 10.0.0.2 only
C. Both 10.0.0.1 and 10.0.0.2 equally
D. No server, error occurs

Solution

  1. Step 1: Understand upstream with backup server

    Main server 10.0.0.1 handles requests first; backup 10.0.0.2 is fallback.
  2. Step 2: Check server availability

    Since 10.0.0.1 is up, nginx sends all requests there, ignoring backup.
  3. Final Answer:

    10.0.0.1 only -> Option A
  4. Quick Check:

    Backup used only if main down [OK]
Hint: Backup server used only if main server fails [OK]
Common Mistakes:
  • Assuming backup server shares load
  • Thinking backup server is always active
  • Believing nginx sends requests to both simultaneously
4. You have this nginx upstream configuration:
upstream backend {
    server 192.168.0.1 backup;
    server 192.168.0.2;
}

What is wrong with this configuration?
medium
A. Backup keyword is misspelled
B. No semicolon after server lines
C. IP addresses are invalid
D. Nothing is wrong with this configuration

Solution

  1. Step 1: Validate syntax and parameters

    All server lines have correct syntax, valid IPs, proper semicolons, and correct backup usage.
  2. Step 2: Check server order

    Position of backup servers does not matter; nginx ignores them unless all main servers fail.
  3. Final Answer:

    Nothing is wrong with this configuration -> Option D
  4. Quick Check:

    Backup position irrelevant [OK]
Hint: Backup servers can be listed anywhere [OK]
Common Mistakes:
  • Thinking backup servers must be listed after main servers
  • Believing server order causes failures
  • Assuming 192.168.x.x IPs are invalid
5. You want nginx to send traffic to server1 and server2 normally, but use backup1 and backup2 only if both main servers fail. Which configuration correctly sets this up?
hard
A. upstream backend { server backup1; server backup2; server server1; server server2; }
B. upstream backend { server server1; server server2; server backup1 backup; server backup2 backup; }
C. upstream backend { server server1 backup; server server2 backup; server backup1; server backup2; }
D. upstream backend { server server1; server backup1; server server2; server backup2; }

Solution

  1. Step 1: Identify main and backup servers

    Main servers are server1 and server2; backup servers are backup1 and backup2.
  2. Step 2: Apply correct syntax and order

    Main servers listed first without backup, backups listed after with backup keyword.
  3. Step 3: Verify options

    upstream backend { server server1; server server2; server backup1 backup; server backup2 backup; } correctly lists main servers first, backups with backup keyword after.
  4. Final Answer:

    upstream backend { server server1; server server2; server backup1 backup; server backup2 backup; } -> Option B
  5. Quick Check:

    Main servers first, backups last with 'backup' keyword [OK]
Hint: List main servers first, backups last with 'backup' keyword [OK]
Common Mistakes:
  • Placing backup servers before main servers
  • Missing 'backup' keyword on backup servers
  • Marking main servers as backup by mistake
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard