NGINX supports WebSockets by allowing a tunnel to be setup between a client and a backend server. In order for NGINX to send the Upgrade request from the client to the backend server, Upgrade and Connection headers must be set explicitly. For example:
# WebSocket proxying
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
# The host name to respond to
server_name cdn.domain.com;
location / {
# Backend nodejs server
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}