Error during WebSocket handshake, I use nginx

Technical Support
  • I've searched for a whole day, and of course I searched in nodeBB first. But I cannot find a post that solves my problem. So I ask for help here. Please do not mark my post as spam again.

    I've read nginx config document, and I've done most of the configs. But it still doesn't work . The queer thing is that it works well in my mac, but it does not work in my server.
    My server is CentOS release 6.6 (Final).

    And I cannot understand these things:
    /path/to/nginx/sites-available/* -- files here must be aliased to ../sites-enabled(my nginx does not have such directory)
    /path/to/nginx/conf.d/*.conf -- filenames must end in .conf
    /path/to/nginx/httpd.conf -- if all else fails (What does it mean?)

    Here is my error informations:
    WebSocket connection to 'ws://test1-forum-acp.ezsport.cc/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

    Here is my config:

    user              nginx;
    worker_processes  2;
    
    error_log  /mnt/logs/nginx/error.log;
    
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /mnt/logs/nginx/access.log  main;
        server_names_hash_bucket_size   64;
    
        sendfile        on;
        keepalive_timeout  65;
        server {
            listen       80;
            server_name  localhost;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
       
        include /etc/nginx1.8/conf/conf.d/*.conf; 
    }
    
    

    conf.d/ includes config file blow

    map $http_upgrade $connection_upgrade {
    	default upgrade;
    	''      close;
    }
    
    server {
            listen 80;
            client_max_body_size 5m;
    
            server_name  test1-forum-acp.ezsport.cc;
            location / {
    		proxy_set_header X-Forwarded-Proto $scheme;
    		proxy_set_header X-NginX-Proxy true;
    
    		proxy_pass http://acp_io_nodes;
    		proxy_redirect off;
    
    		# Socket.IO Support
    	        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;
            }
    }
    upstream acp_io_nodes {
        ip_hash;
        server 127.0.0.1:5568;
    }
    
  • 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 🙂

  • @jenkler works fine?

  • Strange, i responded to the "try to reply" message but its gone now. Nevermind!

  • @jenkler well, that's because I edit it. 😀

  • 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) in sites-available to sites-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 because my nginx has other services. I have to follow previous configs. Anyway, I'll try what you said.

  • @pitaj
    My nginx dir only has these dirs:

  • @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.

  • @pitaj Depending on the OS nginx is set up differently, you can't push sites_enabled/ and sites_available/ on people. It's mostly a Debian/Ubuntu thing 😃

    @lqzerogg Can you show us your config.json?

  • @julian thx, I've solved this problem. But I can't post my solution because the stupid robot marked my post as spam.

  • 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
    
  • ... do you need to set cookieDomain? You're probably better off unsetting that config instead of commenting out code.


Suggested Topics


  • 0 Votes
    1 Posts
    168 Views

    So.... I followed the instructions using this:
    https://docs.nodebb.org/installing/cloud/heroku/
    and everything seemed to go smoothly, I started the app using Heroku, and the first page I get is:
    579d24db-0f66-43a0-87f4-ccc120675e25-image.png
    instead of the usual homepage, and it keeps telling me this message:
    238f50e5-e4b5-440e-a06e-07157b39dc58-image.png .

    I tried reading through others who had similar issues but failed to find what is wrong with my setup, and not really sure where to start looking as i am new to this. I'd appreciate any help i can get 🙂 thanks for your time

  • 1 Votes
    1 Posts
    840 Views

    Getting issue Version 1.11.2
    Error: misconfigured cors on adding through Upload new picture from url

  • 0 Votes
    1 Posts
    246 Views

    EasyEngine (ee) is a linux shell-script collection, which makes managing your WordPress and Nginx sites on an Ubuntu server easy and fun. Now EE4 using Docker.

    I would like to install EasyEngine + NodeBB like example.com/forum/
    Any ideas how to build it together?

    There have topic https://community.easyengine.io/t/how-to-run-node-js-app-on-v4/11482 about it from EE developer and his explanation looks like very hard. My devops skills still low. Maybe for NodeBB team it will not so hard and we will receive manual how to use it together.

    Installation guides and examples of nginx configurations are welcome.

    Thx!

  • 0 Votes
    4 Posts
    1k Views

    @Krissanawat-Kaewsanmuang you misunderstand, that's just a reference of the code which by default falls back to the user image if there's no topic image.

  • 0 Votes
    1 Posts
    1k Views

    After uptgarding (reinstallation) of nodebb, this plugins return error and don't work at all.
    After app starting, I got this warn message:

    7/11 12:20 [31705] - warn: [meta/dependencies] Bundled plugin nodebb-plugin-dbsearch not found, skipping dependency check.
    17/11 12:21 [31705] - warn: [plugins/nodebb-plugin-sso-github] Hook filter:user.delete is deprecated, please use an alternative
    17/11 12:21 [31705] - warn: [plugins/nodebb-plugin-sso-google] Hook filter:user.delete is deprecated, please use an alternative
    17/11 12:21 [31705] - warn: [plugins/nodebb-plugin-sso-twitter] Hook filter:user.delete is deprecated, please use an alternative

    17/11 12:21 [31705] - warn: [plugins/load] The following plugins may not be compatible with your version of NodeBB. This may cause unintended behaviour or crashing. In the event of an unresponsive NodeBB caused by this plugin, run ./nodebb reset -p PLUGINNAME to disable it.

    nodebb-plugin-imgur nodebb-plugin-sso-facebook nodebb-plugin-sso-github nodebb-plugin-sso-google nodebb-plugin-sso-twitter nodebb-plugin-composer-redactor nodebb-plugin-custom-pages nodebb-plugin-desktop-notifications nodebb-plugin-rss nodebb-plugin-youtube

    17/11 12:21 [31705] - info: [User-Invitations] Initializing User-Invitations...
    17/11 12:21 [31705] - info: [plugins/spam-be-gone] Settings loaded
    17/11 12:21 [31705] - info: [User-Invitations] Synced settings: defaultInvitations=10, restrictRegistration=0, invitedUsers=[], inviteGroup=registered-users
    17/11 12:21 [31705] - warn: [plugin/composer-redactor] Another composer plugin is active! Please disable all other composers.
    17/11 12:21 [31705] - info: NodeBB Ready
    17/11 12:21 [31705] - info: NodeBB is now listening on: 0.0.0.0:4567

    list itemWhen I try to login with Facebook, I got:
    L’URL fournie n’est pas autorisée par la configuration de l’application.: Une ou plusieurs URL fournies ne sont pas autorisées par les paramètres de l’application. Elle(s) doi(ven)t correspondre à l’URL du site ou du Canevas, ou le domaine doit être un sous-domaine de l’un des domaines de l’application.

    With googleplus:
    list item400. That’s an error.
    Error: redirect_uri_mismatch

    list itemWith twitter and github I get the same Error.

    With the ancien version of nodebb, all this sso login worked fine.

    Please can somone help me to resolve this problem ??