📖 Scenario: You manage a website that needs to stay online even if the main server goes down. To do this, you want to set up backup servers using nginx. This way, if the main server is unavailable, nginx will automatically send visitors to a backup server.
🎯 Goal: You will create an nginx configuration that defines a main server and two backup servers. You will configure nginx to try the main server first and use the backups only if the main server is down.
📋 What You'll Learn
Create an nginx upstream block named backend with one main server and two backup servers.
Mark the two backup servers with the backup parameter.
Configure nginx to use the backend upstream for proxying requests.
Print the final nginx configuration to verify the setup.
💡 Why This Matters
🌍 Real World
Websites often need backup servers to stay online during outages. nginx can automatically switch to backup servers to keep the site available.
💼 Career
DevOps engineers and system administrators use nginx upstream and backup servers to build reliable, fault-tolerant web services.
Progress0 / 4 steps
1
Create the upstream block with main server
Create an nginx upstream block called backend with one main server at 192.168.1.10:80.
Nginx
Hint
Use the upstream directive and add the main server inside the block.
2
Add two backup servers to the upstream block
Add two backup servers to the backend upstream block: 192.168.1.11:80 and 192.168.1.12:80. Mark both as backup servers.
Nginx
Hint
Add the backup servers with the backup keyword after the server address.
3
Configure nginx to use the upstream backend
Create a server block that listens on port 80 and proxies all requests to the backend upstream using proxy_pass.
Nginx
Hint
Inside the server block, add a location / block and use proxy_pass http://backend; to forward requests.
4
Print the final nginx configuration
Print the entire nginx configuration to verify the upstream and server blocks are correct.
Nginx
Hint
Use multiple print statements to output each line of the nginx configuration exactly.
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
Step 1: Understand the role of backup servers
Backup servers are fallback servers used only when main servers fail.
Step 2: Analyze the backup keyword effect
Marking a server as backup means it will receive traffic only if main servers are down.
Final Answer:
To use it only if all main servers are unavailable -> Option A
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
Step 1: Recall nginx upstream server syntax
The correct syntax is server [IP] [parameters]; with parameters like backup after IP.
Step 2: Identify correct placement of backup
The backup keyword comes after the IP address in the server line.
Final Answer:
server 192.168.1.10 backup; -> Option C
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
Step 1: Understand upstream with backup server
Main server 10.0.0.1 handles requests first; backup 10.0.0.2 is fallback.
Step 2: Check server availability
Since 10.0.0.1 is up, nginx sends all requests there, ignoring backup.
Final Answer:
10.0.0.1 only -> Option A
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
Step 1: Validate syntax and parameters
All server lines have correct syntax, valid IPs, proper semicolons, and correct backup usage.
Step 2: Check server order
Position of backup servers does not matter; nginx ignores them unless all main servers fail.
Final Answer:
Nothing is wrong with this configuration -> Option D
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
Step 1: Identify main and backup servers
Main servers are server1 and server2; backup servers are backup1 and backup2.
Step 2: Apply correct syntax and order
Main servers listed first without backup, backups listed after with backup keyword.
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.
Final Answer:
upstream backend {
server server1;
server server2;
server backup1 backup;
server backup2 backup;
} -> Option B
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 unknownstrongwhile earning +1 Grip toward your certificate.