0
0
Nginxdevops~20 mins

502 Bad Gateway troubleshooting in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
502 Bad Gateway Troubleshooter
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding the cause of 502 Bad Gateway in Nginx
What is the most common cause of a 502 Bad Gateway error when using Nginx as a reverse proxy?
ANginx configuration file syntax error
BThe backend server is down or not responding
CClient browser cache is corrupted
DDNS server is unreachable
Attempts:
2 left
💡 Hint
Think about what happens when Nginx tries to connect to the backend server.
💻 Command Output
intermediate
2:00remaining
Identifying backend server status from Nginx error log
Given the following Nginx error log snippet, what does it indicate about the backend server?
Nginx
2024/06/01 12:00:00 [error] 1234#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.10, server: example.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "example.com"
AThe backend server at 127.0.0.1:8080 is refusing connections
BNginx has a syntax error in its config
CThe DNS resolution for example.com failed
DThe client IP 192.168.1.10 is blocked
Attempts:
2 left
💡 Hint
Look at the phrase 'connect() failed (111: Connection refused)'.
Configuration
advanced
2:30remaining
Correcting Nginx upstream configuration to avoid 502 error
Which Nginx upstream configuration will correctly proxy requests to a backend server running on localhost port 3000 and avoid 502 errors if the backend is healthy?
A
upstream backend { server 3000; }
server {
  location / {
    proxy_pass http://backend;
  }
}
B
upstream backend { server 127.0.0.1; }
server {
  location / {
    proxy_pass http://backend:3000;
  }
}
C
upstream backend { server localhost:3000; }
server {
  location / {
    proxy_pass http://127.0.0.1;
  }
}
D
upstream backend { server 127.0.0.1:3000; }
server {
  location / {
    proxy_pass http://backend;
  }
}
Attempts:
2 left
💡 Hint
The upstream server must include both IP and port correctly.
Troubleshoot
advanced
2:00remaining
Diagnosing intermittent 502 Bad Gateway errors
You notice intermittent 502 Bad Gateway errors in Nginx logs with messages about upstream timed out. What is the most likely cause?
ABackend server is slow or overloaded causing timeouts
BNginx configuration file has syntax errors
CClient is sending malformed HTTP requests
DNginx worker processes crashed
Attempts:
2 left
💡 Hint
Timeouts usually mean the backend took too long to respond.
Best Practice
expert
3:00remaining
Best practice to prevent 502 Bad Gateway during backend restarts
Which approach best prevents 502 Bad Gateway errors when restarting backend servers behind Nginx?
ADisable proxy buffering in Nginx
BRestart Nginx every time backend restarts
CUse Nginx health checks and remove unhealthy backends from upstream dynamically
DIncrease client_max_body_size in Nginx
Attempts:
2 left
💡 Hint
Think about how Nginx can avoid sending requests to backends that are down.