Question

Connecting to my websocket server directly works (Chrome or Firefox). Connecting via the Nginx websocket proxy connects, but drops frames. Here is an example of the JSON messages:

<-- {"login" : { "username": "user", "password" : "pass"}}
--> {"loginReply" : { "state": "ok"}}
<-- {"someSetting1" : { "something": "something"}}
<-- {"someSetting2" : { "something": "something"}}  **DROPPED**
<-- {"someSetting3" : { "something": "something"}}  **DROPPED**

Those last three messages are sent immediately after login, but the last two don't make it to the websocket server (~90% of the time). Subsequent messages, work fine, as if nothing was missing.

I have tried Nginx 1.4.7 & 1.5.13

location /websocket {
            proxy_pass http://localhost:8001;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_read_timeout 86400;
}

I have tried proxy_buffering off and on.

Anything else I should try?

Was it helpful?

Solution

After analysing the data stream, Nginx is indeed streaming the data. The difference is Nginx is buffering it into one continuous stream, where as the data from the browsers is fragmented.

The websocket implementation I was using needed fixing.

OTHER TIPS

One additional error I noticed with several websocket implementations is that you need to use "Upgrade" and not "upgrade".

Try changing proxy_set_header Connection "upgrade";

to

proxy_set_header Connection "Upgrade";

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top