# Websocket handshake failing

**URL:** <https://www.ruby-forum.com/t/websocket-handshake-failing/242813>\
**Category:** NGINX\
**Created:** [July 30, 2015, 5:20pm UTC](https://www.ruby-forum.com/t/websocket-handshake-failing/242813 "2015-07-30T17:20:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [July 30, 2015, 5:20pm UTC](https://www.ruby-forum.com/t/websocket-handshake-failing/242813/1 "2015-07-30T17:20:11Z")

</div>

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](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.

Appreciate the help!

Posted at Nginx Forum:

> **[Websocket handshake failing](https://forum.nginx.org/read.php?2,260651,260651#msg-260651)**
>
> 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;...

---

<div class="post-metadata">

**Author:** ![nightcrawler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@nightcrawler](https://www.ruby-forum.com/u/nightcrawler)\
**Post date:** [July 30, 2015, 7:45pm UTC](https://www.ruby-forum.com/t/websocket-handshake-failing/242813/2 "2015-07-30T19:45:38Z")

</div>

Hello!

On Thu, Jul 30, 2015 at 11:19:32AM -0400, nightcrawler wrote:

> with aConnection: Upgrade header as expected, the client gets only  
> 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:

> **[WebSocket proxying](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:

> **[A debugging log](http://nginx.org/en/docs/debugging_log.html)**

–  
Maxim D.

> **[nginx](http://nginx.org/)**
