0
0
Nginxdevops~5 mins

WebSocket proxying in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is WebSocket proxying in nginx?
WebSocket proxying in nginx means forwarding WebSocket connections from clients to backend servers, allowing real-time communication through nginx as a middleman.
Click to reveal answer
beginner
Which nginx directive is essential to support WebSocket proxying?
The directive proxy_set_header Upgrade $http_upgrade; is essential to handle the WebSocket handshake upgrade request properly.
Click to reveal answer
intermediate
Why do we need to set proxy_http_version 1.1; for WebSocket proxying in nginx?
WebSocket requires HTTP/1.1 because it uses the Upgrade header to switch protocols. Setting proxy_http_version 1.1; ensures nginx uses the right HTTP version for the handshake.
Click to reveal answer
intermediate
What headers must nginx forward to support WebSocket connections?
nginx must forward the Upgrade and Connection headers to allow the WebSocket handshake to succeed.
Click to reveal answer
beginner
Show a minimal nginx configuration snippet to proxy WebSocket connections.
location /ws/ {
  proxy_pass http://backend_server;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
}
Click to reveal answer
Which HTTP version must nginx use to proxy WebSocket connections?
AHTTP/3
BHTTP/1.0
CHTTP/2
DHTTP/1.1
Which header tells the server to switch protocols to WebSocket?
AUpgrade
BContent-Type
CAuthorization
DCache-Control
What value should the Connection header have to support WebSocket proxying?
Akeep-alive
Bclose
Cupgrade
Dproxy
In nginx, which directive forwards the Upgrade header from client to backend?
Aproxy_set_header Upgrade $http_upgrade;
Bproxy_pass http://backend;
Cproxy_redirect off;
Dproxy_buffering off;
What happens if nginx does not forward the Upgrade and Connection headers for WebSocket?
AConnection will be faster
BWebSocket connection will fail
CNo effect on WebSocket
Dnginx will cache the connection
Explain how to configure nginx to proxy WebSocket connections.
Think about the headers and HTTP version needed for WebSocket handshake.
You got /4 concepts.
    Why is it important to set the Connection header to 'upgrade' in WebSocket proxying?
    Consider what the Connection header controls in HTTP.
    You got /3 concepts.