WebSocket server settings

388 views Asked by At

I use em-websocket gem in Rails application. WebSocket server runs in the initializer, this is how it looks:

#config/initializers/web_socket.rb
EM.next_tick do
  EM::WebSocket.run(host: '0.0.0.0', port: 8080) do |ws|
    ws.onopen do |request|
      ...
    end

    ws.onclose do
      ...
    end
  end
end

WebSocket server runs when I launch rails server. It works perfectly in development environment, but it doesn't work on testing server, I use Nginx and Passenger there.

Does anybody know how to setup WebSockets with Passenger and Nginx?

Update: I use thin in development environment. On production I use Nginx and Passenger, settings of these tools are usual. I don't have error messages in the logs. In browser console I have following error:

Failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT 

Nginx config:

worker_processes  1;

events {
    worker_connections  1024;
}
http {
    passenger_root /usr/local/rvm/gems/ruby-2.2.2/gems/passenger-5.0.7;
    passenger_ruby /usr/local/rvm/gems/ruby-2.2.2/wrappers/ruby;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  example.com;
        passenger_enabled on;
        rails_env production;
        root /var/www/domains/example.com/www/deployments/current/public;
    }
}

I use usual Ubuntu server.

0

There are 0 answers