Ratchet: Can Ratchet work with Nginx's websocket proxying?

Created on 1 Mar 2013  路  6Comments  路  Source: ratchetphp/Ratchet

Nginx 1.3.13 has websocket support. Is it possible to use it with Ratchet? I tried it and didn't have any luck.

This is part of my .conf file with ratchet running on port 8080


upstream websocket{
         server 127.0.0.1:8080;
}

server {
        location /websocket {
                 proxy_next_upstream error timeout http_502;
                 proxy_pass http://websocket;

                 proxy_http_version 1.1;

                 proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                 proxy_set_header Host $http_host;
                 proxy_set_header X-NginX-Proxy true;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection "Upgrade";

                 proxy_redirect off;
        }
}
question

Most helpful comment

Just did a quick test and it works fine for me. Used this config for it https://gist.github.com/octaflop/4991052 comparing them both it doesn't have the proxy_next_upstream directive.

All 6 comments

What was the problem you ran into?

I get this error when trying to connect to it:

WebSocket connection to 'ws://reversix.us/websocket' failed: Error during WebSocket handshake: 'Connection' header value is not 'Upgrade'

Just did a quick test and it works fine for me. Used this config for it https://gist.github.com/octaflop/4991052 comparing them both it doesn't have the proxy_next_upstream directive.

Thanks for the reply.

I see now that nginx's routing is fine... it's just that Ratchet doesn't send a response for some reason.

So yeah, this is definitely not an nginx or Ratchet issue. I probably broke something when I moved the code to my server.

Well in my case, I cannot get the real_ip to pass it to the websocket....

@Mecanik you have to pass proxy_set_header X-Real-IP $remote_addr; header to your location section.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harveyslash picture harveyslash  路  6Comments

clarkk picture clarkk  路  6Comments

dschissler picture dschissler  路  3Comments

elovin picture elovin  路  3Comments

ThePatzen picture ThePatzen  路  3Comments