Load Balancer: nginx in Front of Two App Servers and a Standby
MediumLFCS Prep20 minThe shop app runs as three app servers on this box: app-1 on 127.0.0.1:9101 and app-2 on 127.0.0.1:9102 are the primaries, and app-3 on 127.0.0.1:9103 is a standby. Make nginx the load balancer on port 80:
1. http://127.0.0.1/ spreads requests across app-1 and app-2 in turn.
2. app-3 gets no traffic while either primary is up, and takes over when both are down.
3. If one primary dies, users must not see errors.
4. The config lives in nginx's own config files, passes nginx -t, and nginx is running.
Each app server answers with its name, so curl -s http://127.0.0.1/ shows who served you. s9-apps status lists the app servers, s9-apps stop app-1 stops one so you can test failover, and s9-apps ensure starts any that are down. The stock default site is still enabled. This box has no systemd, so use service nginx start or service nginx reload (systemctl reload nginx on a real host). Grading sends real requests through nginx while it stops and restarts app servers. The ticket is in /root/case/brief.txt.
- Define an nginx upstream pool and proxy to it
- Keep a standby server out of rotation with backup
- Verify failover by taking backends down
Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.
