Websocket handshake failing
Maxim Dounin
mdounin at mdounin.ru
Thu Jul 30 17:45:19 UTC 2015
Hello!
On Thu, Jul 30, 2015 at 11:19:32AM -0400, nightcrawler wrote:
> I'm trying to enable websocket communication between client and server and
> have nginx as proxy. Ive applied the following congiguration changes to
> websocket sites-enabled conf to allow for websocket proxy:
> proxy_set_header Upgrade $http_upgrade;
> proxy_set_header Connection "upgrade";
> proxy_set_header X-Forwarded-For $http_x_forwarded_for;
> proxy_set_header Host $http_host;
> proxy_pass http://mywebsite;
>
> Although the server receives the Connection: Upgrade header and responds
> with aConnection: Upgrade header as expected, the client gets only
> Connection: keep-alive and I see the following error on js-console
>
> WebSocket connection to 'wss://mywebsite.dev/cometd/' failed: Error during
> WebSocket handshake: 'Connection' header value must contain 'Upgrade'
>
> I feel that nginx might not be proxying the response correctly either due to
> incorrect response or bad config.
>
> Can someone help me out with debugging this? A lot of places where I see
> this issue, usually the proxy does not support the websocket handshake which
> causes the handshake to fail.
Connections upgrades are supported by nginx proxy starting with
nginx 1.3.13. Make sure you are using recent enough version, not
something from Debian oldstable.
You also need to configure nginx properly. Detailed documentation
can be found here:
http://nginx.org/en/docs/http/websocket.html
In the config snippet you've provided at least "proxy_http_version 1.1;"
seems to be missing.
If the above won't help, consider looking at nginx debugging logs.
See here for some basic hints:
http://nginx.org/en/docs/debugging_log.html
--
Maxim Dounin
http://nginx.org/
More information about the nginx
mailing list