node.js - socket.io trouble in nginx -


socket.io v. 1.0
nginx v 1.4.6
nodejs v 0.10.32
ubuntu v 14.04
droplet ip (for example): 123.45.678.90
nodejs port listen on: 3001
domain: mydomain.com

everythigs works correctly both on localhost in webstorm , on droplet address like: 123.45.678.90:3001. problems begin when try bind domain , nginx follow config:

server {      listen 80;        server_name mydomain.com;        location / {          proxy_pass http://localhost:3001;          proxy_http_version 1.1;          proxy_set_header host $host;          proxy_cache_bypass $http_upgrade;      }  }

when try connect mydomain.com browser, works correct, see message:

{ host: 'mydomain.com',    connection: 'close',    'accept-encoding': 'gzip, deflate',    'user-agent': 'webindex',    accept: 'text/html' }    /var/www/bm/socket/index.js:29  				var sid = socket.request.headers.cookie.split('express.sid=s%3a')[1].split  				                                        ^  typeerror: cannot call method 'split' of undefined

here socket/index.js, part includes io.use:

io.use(function(socket, next){                  async.waterfall([                          function(callback){                                  console.log(socket.request.headers);                                  var sid = socket.request.headers.cookie.split('express.sid=s%3a')[1].split('.')[0];                                  console.log(sid);                                  sessionstore.load(sid, function(err, session){                                          if (arguments.length == 0) {                                                  return callback(null, null);                                          } else {                                                  return callback(null, session)                                          }                                  });                          },                          function(session, callback){                                  socket.handshake.session = session;                                  callback(null);                          }                  ], function(){                          if (socket.handshake.session) {                                  return next();                          } else {                                  console.log('error, careful');                                  return next(new error('not authorized'));                          }                  });          });

what happend? tried catch 'webindex' , change part of io.set:

console.log(socket.request.headers);  if (socket.request.headers['user-agent'] == 'webindex') {    return callback(null, null);  }  var sid = socket.request.headers.cookie.split('express.sid=s%3a')[1].split('.')[0];  console.log(sid);

as result, got browser on address mydomain.com:

websocket connection 'ws://mydomain.com/socket.io/?eio=3&transport=websocket&sid=qzyl8ou8qn556_weaaac' failed: error during websocket handshake: unexpected response code: 400

a few seconds socket.io worked correctly got 400 error message. ideas?

i solved problem full reinstalling nginx:

// delete nginx , linked packages:  sudo apt-get remove nginx*  // delete nginx working directories , logs: sudo rm -rf /etc/nginx/ /usr/sbin/nginx /usr/share/man/man1/nginx.1.gz  // delete remaining nginx files apt base: sudo apt-get --purge autoremove nginx && sudo dpkg --purge nginx  // reinstall nginx pure config files sudo apt-get -o dpkg::options::=--force-confmiss --reinstall install nginx 

and works!


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -