0
0
Nginxdevops~30 mins

Backup servers in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Backup servers
📖 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
Need a 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
Need a 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
Need a 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
Need a hint?

Use multiple print statements to output each line of the nginx configuration exactly.