Error during WebSocket handshake, I use nginx
-
well, though nodebb websocket cannot be connected, a simple websocket server I wrote can be connected. I use the same config :
upstream acp_io_nodes { #ip_hash; server localhost:3434; } server { listen 80; server_name test1-forum-acp.ezsport.cc; location / { proxy_pass http://acp_io_nodes; proxy_read_timeout 300s; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } }
here is my server's code:
console.log("Server started"); var Msg = ''; var WebSocketServer = require('ws').Server , wss = new WebSocketServer({port: 3434}); wss.on('connection', function(ws) { ws.on('message', function(message) { console.log('Received from client: %s', message); ws.send('Server received from client: ' + message); }); });
Hope someone will rescue me soon.
-
Works fine
-
Strange, i responded to the "try to reply" message but its gone now. Nevermind!
-
The normal way to configure nginx is to create an nginx config file in
/path/to/nginx/sites-available/
. You can copy one of the templates from docs.nodebb.org.You then need to create a symlink from the file (I'll call it
forum.example.com
) insites-available
tosites-enabled
ln -s /path/to/nginx/sites-available/forum.example.com /path/to/nginx/sites-enabled/forum.example.com
You don't seem to be using our nginx templates at all. Any reason why?
-
@pitaj My nginx directory only has these sub dirs:
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
And even I do what you said, nginx still not working. I seems that my nginx can only set config by conf/nginx.conf file. sites-available/ and sites-enabled/ seems useless to me.
-
After a hard time debugging, I found out that it's not because of nginx setting. It is because I set a "cookieDomain" config. After I remove this one, it works properly. I modify source code and fix this problem. Maybe it's not a good solution, but it works for me.
-
file: src/socket.io/index, line:45
// other code // added code, force to resign variable domain = parsedUrl.hostname; // comment these codes // if (!domain) { // domain = parsedUrl.hostname; // cookies don't provide isolation by port: http://stackoverflow.com/a/16328399/122353 // } // other code