0

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.

Sergei Struk
  • 358
  • 4
  • 12
  • What errors are you getting? What application server are you using in development and in production (puma? unicorn? thin?)? What settings do you now have with Nginx? help us help you. – Myst Nov 19 '15 at 06:26
  • P.S. If you're using two ports for your application (one for websockets and another for Http-Rails) **you might not be able to deploy your application on some systems** (i.e. Heroku), which allow your application a single port. Consider using solutions that allow you to use a single application server for both websockets and Http (i.e. [Plezi](www.plezi.io), which is my pet project or a websockets middleware). – Myst Nov 19 '15 at 06:29
  • @Myst, Please see updated information about configs and error message. I use usual Ubuntu server. – Sergei Struk Nov 19 '15 at 16:47
  • @Myst, I've tryied to use 'plezi', but had problem with routing. Can use see this question? http://stackoverflow.com/questions/33810542/plezi-route-in-rails-app – Sergei Struk Nov 19 '15 at 17:30

0 Answers0