add the following into the server block:
# necessary stuff for websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “Upgrade”;# extras?
proxy_set_header Host $host;
proxy_read_timeout 86400;
- first line tells Nginx to use 1.1 when communicating to the Node backend, which is required for WebSockets
- next two tell Nginx to respond to the Upgrade request which is initiated over HTTP by the browser when it wants to use a WebSocket
Example Server Block
server {
listen 8080;
server_name chat.marcuschiu.com;
location / {
proxy_pass http://192.168.0.2:8080;
# necessary stuff for websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
# extras?
proxy_set_header Host $host;
proxy_read_timeout 86400;
}
}