0
0
Nginxdevops~20 mins

WebSocket proxying in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WebSocket Proxying Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
WebSocket connection upgrade headers
You have an Nginx configuration proxying WebSocket traffic. What is the output of the following curl command headers when connecting to the WebSocket endpoint?

curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" http://localhost/ws
AHTTP/1.1 200 OK\nContent-Type: text/html
BHTTP/1.1 400 Bad Request\nContent-Type: text/plain
CHTTP/1.1 101 Switching Protocols\nUpgrade: websocket\nConnection: Upgrade
DHTTP/1.1 404 Not Found\nContent-Type: text/html
Attempts:
2 left
💡 Hint
WebSocket connections require HTTP 101 status with upgrade headers.
Configuration
intermediate
2:00remaining
Correct Nginx config for WebSocket proxy
Which Nginx configuration snippet correctly enables WebSocket proxying to backend at ws://backend:8080/ws?
Aproxy_set_header Upgrade $http_upgrade;\nproxy_set_header Connection "upgrade";\nproxy_pass http://backend:8080/ws;
Bproxy_set_header Upgrade websocket;\nproxy_set_header Connection keep-alive;\nproxy_pass http://backend:8080/ws;
Cproxy_set_header Upgrade $http_upgrade;\nproxy_set_header Connection "close";\nproxy_pass http://backend:8080/ws;
Dproxy_set_header Upgrade $connection_upgrade;\nproxy_set_header Connection "close";\nproxy_pass http://backend:8080/ws;
Attempts:
2 left
💡 Hint
The Upgrade header must use the client header variable, and Connection must be 'upgrade'.
Troubleshoot
advanced
2:00remaining
WebSocket connection fails with 400 Bad Request
You configured Nginx to proxy WebSocket but clients get HTTP 400 Bad Request errors. Which is the most likely cause?
AClient is using HTTP/2 instead of HTTP/1.1
BBackend server is down and not responding
CNginx is missing SSL certificate configuration
DMissing or incorrect Upgrade and Connection headers in proxy_set_header directives
Attempts:
2 left
💡 Hint
WebSocket handshake requires specific headers to upgrade the connection.
🔀 Workflow
advanced
2:00remaining
Steps to enable WebSocket proxying in Nginx
What is the correct order of steps to enable WebSocket proxying in Nginx?
A2,3,1,4
B1,3,2,4
C2,1,3,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Headers must be set before proxy_pass, then reload Nginx.
Best Practice
expert
2:00remaining
Best practice for WebSocket timeout settings in Nginx
Which Nginx configuration snippet follows best practices to avoid WebSocket connection drops due to timeouts?
Aproxy_read_timeout 30s;\nproxy_send_timeout 30s;
Bproxy_read_timeout 3600s;\nproxy_send_timeout 3600s;
Cproxy_connect_timeout 5s;\nproxy_send_timeout 10s;
Dproxy_connect_timeout 60s;\nproxy_read_timeout 10s;
Attempts:
2 left
💡 Hint
WebSocket connections are long-lived and need longer timeouts.