ActionCable / Websocket not working with Puma - ruby-on-rails

The problem
In development I'm having split processes between my Rails server and ActionCable.
➜ backend git:(dev) bundle exec puma cable/config.ru -p 1337
Puma starting in single mode...
* Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
* Min threads: 0, max threads: 16
* Environment: development
My configuration is pretty classical
# cable/config.ru
require_relative '../config/cable_environment'
Rails.application.eager_load!
run ActionCable.server
And in my development.rb I've got those
# Set Action Cable server url for consumer connection
config.action_cable.url = 'wss://localhost:4001'
config.action_cable.allowed_request_origins = [
'https://localhost:4000',
]
It looks like it's working. In parallel of that I use some split front-end in VueJS to listen to the websockets. You should know this whole configuration was working before a few days back.
When I try to listen to sockets from the front-end it does this
action_cable.js?f5ee:241 WebSocket connection to 'wss://localhost:4001/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
What I know
The SSL is correctly configured (as I said it was actually working before) and the configuration seems really fine. I'm also not the only one working on this Rails project but the only one to face this issue.
When I try to check it the port is in use I do the following
lsof -ti:4001
I noticed no process is running at all and I've no idea how to troubleshoot this. As the websocket server seems to be intern to ActionCable, I don't really know how to search what crashes, there's no error displayed, puma is up and running, but the websockets aren't.
What I tried
I can't recollect exactly what I did in the last few days which could have broken the Websockets, so I tried many things
I've tried to change the configuration in many, many ways, but I pasted the original one here. Basically ran the whole documentation multiple times and tried all combinations i could think of
I've tried to change the port, or endpoint
I changed the SSL certificates which are self-hosted (and working) and produced new ones, it doesn't seem to be linked to the problem
I've tried to downgrade Puma but it didn't change anything.
I've tried to reinstall the project entirely in a fresh directory but it still doesn't work.
I've also reinstalled multiple times Ruby via RVM and tried a few versions, without success.
I even ended up upgrading my computer to MacOS Mojave in a desperate move, didn't move the problem one bit.
What I don't know
I don't know anything about the mechanism to spawn Websockets via ActionCable. Why isn't there any error ? How does it work ? Did I miss something in my configuration? Does it interact with anything else like NPM / Node / Apollo Which could have changed on my computer? I work on multiple projects with multiple technologies, it's pretty hard to find an exact origin ...
If you need more informations, just let me know. Thanks for your time.

The solution
I figured I had an Nginx setup to make my sockets work with TLS which I had forgotten about. If you end up here, you may be in the same case.
You can check that out by doing nginx -t in your console and open the file - if any present - in your IDE.
# /usr/local/etc/nginx/nginx.conf
...
server {
listen 5212 ssl;
server_name localhost;
ssl_certificate /Users/loschcode/Desktop/some-path/ssl/server.crt;
ssl_certificate_key /Users/loschcode/Desktop/some-path/ssl/server.key;
location / {
rewrite ^(.*) https://localhost:5214$1 permanent;
}
}
...
I recently changed the directory I used to work on the project, which made a wrong path to the certificate, therefore my issue. Fixing the path made it work.

Related

moving app over to a different server

I am trying to move an app over from an older server to another no so much older server. As far as I can tell the old app was (for some reason I did this) running on Unicorn, with ruby version 1.8.6. The new server supports 186 and 193 so it shouldnt be a problem. but I continuously get an error when i try to run the site.
http://omnimart.myitcrm.biz/
I have searched the web and couldnt find an exact post describing this error and a solution for it.
I tried to put 186 in nginx so that it would use the correct version of ruby, but I also get 193 showing up in the environment variables, and I figured that may be the problem, but I tried tracing these environment variables back to see where there were set and I couldnt find it anywhere. Could that be the problem?
nginx conf:
server {
passenger_ruby /home/purge/.rvm/gems/ruby-1.8.6-p420/wrappers/ruby;
listen 80;
server_name omnimart.myitcrm.biz;
root /home/purge/www/omnimart/current/public;
passenger_enabled on;
}
The site is currently running now so it isn't an emergency but I would like to resolve this so i can shut down one node that only has one remaining app running on it.
Any ideas on what I can do to fix this one?

Deploying Rails/Passenger via nginx

I'm having a hard time figuring out where I'm going wrong in trying to deploy a Rails app via nginx. Rails is accessible via site.com:3000 (after starting it with rails server), and site.com:80 displays the standard nginx "working, but further configuration required" page. I've spent a few hours trawling the documentation trying to figure our how to get my Rails app accessible at :80 rather than :3000, but to no avail.
I think it's most likely that I'm misunderstanding how nginx, Passenger, and Rails work together, and have therefore configured my nginx.conf incorrectly (one page I found implied that I shouldn't both be using nginx and running rails server). Any and all help is hugely appreciated.
Possibly relevant version numbers:
Rails 4.1.4
Ruby 2.1.2p95
CentOS 6.5
nginx 1.6.0
nginx.conf partial: http://pastebin.com/A3JD09pr
I'm new at this, so it turned out that a couple things were up:
I needed to put export rvmsudo_secure_path=1 in my .bashrc instead of just running it once, following up with source ~/.bashrc in the terminal. This allowed me to run "rvmsudo" commands to start on port 80 rather than the default 3000.
I had both nginx and Rails competing for port 80, so I had to stop nginx's static page server to allow that. Simple as nginx stop.

Rails Capistrano: Steps after Deployment (Getting remote server up)

Ok. This should be my easiest stackoverflow post yet.
So I have Capistrano installed and configured properly. I've managed a successful deployment to my remote server (incidentally that remote server is running rails 4.0 and the local one was on 3.2.13). All my files appear to have been successfully transferred to my liquid_admin/current directory (they used to just be in the liquid_admin directory... but whatever.)
So what do I do now? How do I get rails server to load the app in liquid_admin/current?
If I try to do "rails server" it just tells me:
usage: rails new app_path
Would that actually overwrite my old app? Basically all I want to do is load the app in the "current" directory. Run the server. Should be a no-brainer right? :)
For a single website on a small server, passenger and Ngnix look like winners.
sudo passenger-install-nginx-module
And then on the Nginx sites folder:
server {
listen 80;
server_name www.mysite.com;
root /rails_website_root/public;
passenger_enabled on;
}
Then just start Ngnix (usually you put it on autostart)
The default server that you probably use in development - WEBrick - is not suitable for production. Some options that you have are:
Unicorn
Thin
You also need Apache or Nginx 'in front' of your Rails server.
All this is well explained in tons of guides, books, railscasts etc, so please go and google it.

Bitnami Rails Nginx Thin - The service is not available. Please try again later

I'm trying to get a Bitnami Rails stack running with Nginx and 5 Thin app servers.
I have the Thin app servers running OK and I've got Nginx started and it's connected to the 5 Thin servers.
But, some code is giving me "The service is not available. Please try again later." html when I access my app from a browser. I don't know where the code is that's giving me that message.
I have the Nginx server listening on port 80.
This is my nginx.conf file: https://dl.dropbox.com/u/35302780/nginx.conf
Thanks for the help!
Your config seems fine, except those 2 if statements because IF is evil inside location block. You may want to fix that.
Seems that you are using a 3rd party upstream module. Try to uninstall that module and use the normal upstream module.

Mac OS X + Rails 3.1 + Unicorn + HTTPS

Here is my setup:
Mac OS X 10.6
Ruby 1.8.7
Rails 3.1
I have a Rails 3.1 application that starts with Unicorn every time this machine starts up (via a .plist in /Library/LaunchDaemons). The .plist essentially does this:
cd /my_application_directory
sudo unicorn -E production -p 80
And everything's working fine. However, I'd like to be able to set up SSL so that traffic is encrypted. I don't need a real certificate signed by a real CA, because the application is only accessible over a local network.
I've found articles like this one on generating certs, but I'm not sure where to go from there (or even if that's the correct starting place).
For my basic needs, I've found the .plist method to be much easier to work with than something like Phusion Passenger, so I'd like to continue doing it that way if possible.
Any help would be greatly appreciated!
I don't believe Unicorn supports being an SSL endpoint, so you're going to need another process to decrypt/encrypt the traffic for you.
On Mac, it's probably easiest to use apache, because it's already installed.
Sorry to not have detailed steps, but you're looking to do the following:
Change the port unicorn listens on, to prevent conflicts with apache.
Set up Apache to serve SSL, just like your linked reference.
Also set up apache to proxy requests to be handled by Unicorn, on the new port you setup. This involves the ProxyPass (and possibly ProxyPassReverse) directive.
Configure apache to start when the Mac boots.

Resources