Running Rails App using Puma over ssl in windows - ruby-on-rails

I am trying to run my rails application using Puma over ssl in Windows ServerR2. I followed an answer of this question. I have installed puma with the SSL directory and I run puma using
>puma -b 'ssl://127.0.0.1:3000?cert=C:\Sites\server.crt&&key=C:Sites\server.key' -e development -S puma -C config\puma.rb
Also, I have created the cert and key, using this link. But I get the error
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/puma-2.15.3/lib/puma/binder.rb:131:in `check': SSL not available in this build (StandardError)

works great in rails 5.2.3 and puma 3.12
gem uninst puma
ridk exec pacman -S mingw-w64-x86_64-openssl
gem inst puma

Related

Puma Rails server won't start in daemon mode on MacOS 13 Ventura after update from MacOS 12

I just updated from MacOS 12.x to 13.0.1
Starting a Rails app with
➜ rails s
works fine
=> Booting Puma
=> Rails 5.2.8.1 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.6 (ruby 2.6.6-p146), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
But when I try with
➜ rails s -d
Output stops at
=> Booting Puma
=> Rails 5.2.8.1 application starting in development
=> Run `rails server -h` for more startup options
And no server is started
➜ ps -ef | grep puma
501 69877 51917 0 6:45 ttys000 0:00.00 grep puma
➜ ps -ef | grep rails
501 72493 51917 0 6:49 ttys000 0:00.00 grep rails
Well, I found a workaround. This is by no means perfect but if it helps anyone with the same problem:
nohup rails s </dev/null >/dev/null 2>&1 &
The & at the end will make it run in the background. All output/input goes to/from /dev/null and nohup makes sure it will run even after you quit the session.
The reason has nothing to do with the fact that you updated to MacOS Ventura.
Puma daemonization has been removed without replacement since version 5.0.0, and it has been extracted to the puma-daemon gem, which currently works only with Puma version ~> 5.
Therefore now you have two ways to make it work: with puma-daemon, or put it in no hanghup background mode.
METHOD 1: USING PUMA DAEMON GEM
bundle add puma-daemon
Add these line to your application’s Gemfile:
gem 'puma-daemon', require: false
gem 'puma', '~> 5'
Add these lines to config/puma.rb:
require 'puma/daemon'
daemonize
and ensure you have set up at least one worker (workers 1)
Now you should be able to run puma webserver as a daemon with rails server (please notice that you must remove any -d or --daemonize from the command line)
PUT IT IN NO HANGHUP BACKGROUND MODE
Just run rails server --no-log-to-stdout & to put the server in background and stop the output, and enclose it in a nohup >/dev/null command to get rid of the nohup.log file:
nohup rails server --no-log-to-stdout >/dev/null &
This method works with any Puma version and doesn't require the gem.
Don't mess around with the two ways.

Puma compiled without SSL support (RuntimeError) Windows

I want to start Puma (v.5.2.2) using SSL in on Windows on Rails 6.
When I execute:
bundle exec puma
I get the following error:
Puma compiled without SSL support (RuntimeError)
I have openssl installed:
>openssl version
OpenSSL 1.1.1j 16 Feb 2021
In the file puma.rb, I inserted:
ssl_bind '0.0.0.0', 3000, {
key: 'mykey.key',
cert: 'mykey.crt',
verify_mode: 'none'
}
I generated mykey.key and mykey.crt and put them in Rails root folder.
What I've already tried, without success:
I reinstalled Puma after the installation of openssl
I ran the server using this command: rails s -b "ssl://localhost:3000?key=mykey.key&cert=mykey.crt"
I tried Puma version 4.x.x
> ruby -rpuma -e "puts Puma.ssl?"
false
gem install puma
> ruby -rpuma -e "puts Puma.ssl?"
true

Rails SSL while running only Puma on EC2 AWS instance

Specs: Rails 4.2.4, Ruby 2.1.9, running puma, EC2 instance in production mode
I have an SSL certificate that I want to install on my server but using techniques like this one yields no results
rails s puma -b 'ssl://0.0.0.0:9292?key=path_to_key.key&cert=path_to_cert.crt&verify_mode=none&ca=path_to_root_bundle.crt'
How to configure Rails with Puma to use SSL?
also
RAILS_ENV=production rvmsudo -E rails s puma -b "ssl://0.0.0.0:9292?key=${KEY_PATH}&cert=${CERT_PATH}&verify_mode=peer&ca=${CERT_BUNDLE_PATH}" -p 80
Instead of a functioning server I get
Puma starting in single mode...
* Version 3.2.0 (ruby 2.1.9-p490), codename: Spring Is A Heliocentric Viewpoint
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://ssl://0.0.0.0:9292?key=~/evslideshow.key&cert=~/e3b162f57ea48f91.crt&verify_mode=peer&ca=~/gd_bundle-g2-g1.crt:80
Exiting
> /home/ec2-user/.rvm/gems/ruby-2.1.9#slideshow/gems/puma-3.2.0/lib/puma/binder.rb:240:in
`initialize': getaddrinfo: Name or service not known (SocketError)
Now my mind is playing with different options. Am I just missing some fundamental aspect of using puma here? The puma documentation is very scared which is why I'm asking here. Or I could use Nginx because it seems like there is alot of documentation on the internets on setting that up with SSL certificate.
If there is a simpler fix for puma then I will just use that.
Found the solution by reading through some of the issue pages on puma's Github page. Apparently we must call puma directly, and not through rails server, despite what was said here in this old stackoverflow answer
The working code is
RAILS_ENV=production rvmsudo -E puma -d -b "ssl://0.0.0.0:443?key=${KEY_PATH}&
cert=${CERT_PATH}&verify_mode=peer&ca=${CERT_BUNDLE_PATH}" -p 80
Make sure to turn on config.force_ssl in your production config file as well.

Devise compatibility issue on Nginx server with Rails

I have just installed devise on my Ruby on Rails project, it worked perfect on localhost, but when i did the same on Live Server then it started throwing me following error:
undefined method `devise_for' for #<ActionDispatch::Routing::Mapper:0x007facfbc96e18>
i have already restarted the Nginx server by using this command:
sudo /etc/init.d/nginx restart
but no effect.
Thanks.
Note:
Rails version is Rails 4.2.7.1
Ruby version is ruby 2.2.4p230
Aha! finally...
I just stop and start the puma and it's started working. I ran the following commands:
ps aux | grep puma
kill -s SIGUSR2 17562
bundle exec puma -e development -d -b unix:///home/democraticags/digitalammo/shared/sockets/puma.sock
Anyways thanks to all of you who devoted their precious time :)

quickly starting up a rails app on a new server; "No command 'puma' found"

I am trying to quickly set up a rails server. I have an app that I have working an running on my personal computer. Running rails server launches it in localhost:3000 with no issues.
I am trying to start a server on a server to an external IP. So, I followed the instructions here: http://luugiathuy.com/2014/11/setup-nginx-puma-on-ubuntu/ with no issue until I ran: puma -e production -d -b unix:///tmp/app_name.sock --pidfile /tmp/puma.pid and got:
No command 'puma' found, did you mean:
Command 'pump' from package 'pump' (universe)
Command 'pumpa' from package 'pumpa' (universe)
Command 'duma' from package 'duma' (universe)
I have run: gem install puma and bundle install I have added gem 'puma' to my gemfile.
If I visit the external IP of the server I get the nginx error of:
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
which makes sense since puma isn't running.
Solved it:
`/bin/bash --login`
I believe this worked because before I was not "logged in" to the user that had puma installed

Resources