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.
Related
im working on linux, on a project with ruby on rails.
I have a probléme when i use rails s.
Normaly when i do rails s i can see that :
Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.5 (ruby 2.6.3-p62), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
and i can see my project on localhost 3000
But now, on my current project, its juste do :
=> Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
Nothing more, no error message and i just cant acces to my project on localhost3000.
I tryed to specify a port with rails s -p 3000 or a PID with rails -P ... but its didnt changed nothing
i tryed rake rails:update:bin but it didnt changed anything also
Do you have any idea of what i could do for solve my problem and work agan localy on my projet?
Thank's
I guess your errors (std::err) are hidden from console.
You must be having this error
=> A server is already running. Check /YourProjectPath/tmp/pids/server.pid.
go to tmp/pids/server.pid, You will find a server ID there. Run the following command on your terminal with your server ID.
i.e:
$ kill 13455
//where 13455 is server ID for my project.
if it doest not work. Restart your PC.
You can use webrick server instead of puma server using rails s webrick
I'm trying to run a Rails 6 app on AWS Elastic Beanstalk, but I get from puma log the following (repeats every few seconds)
[21776] + Gemfile in context: /var/app/current/Gemfile
[21776] Early termination of worker
The version numbers:
Rails 6.0.3.3
puma 4.3.5
ElasticBeanstalk Ruby 2.7 running on 64bit Amazon Linux 2/3.1.1
ruby 2.7.1p83
The server is unresponsive from outside the instance, and there's nothing on log/production.log.
Running on a dev machine on production mode there's no errors, and the database is reachable (no migration failure).
Running on the AWS instance the command bundle exec puma -p 3000 -e production I get
Puma starting in single mode...
Version 4.3.5 (ruby 2.7.1-p83), codename: Mysterious Traveller
Min threads: 5, max threads: 5
Environment: production
Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
so there's no obvious error that may cause the worker to halt.
How can I find out what's causing the workers to fail?
Edit 1:
I ran Rails console on the instance and found that the environment variables are missing - e.g. the production database user/pass/host. Once I hardcoded them I could connect to the database.
I suspect the absence of other environment variables is making the app crash.
A user on AWS forum had the answer.
Setting in my Gemfile
gem "nio4r", "= 2.5.2"
fixed the issue.
I was watching a (albeit old) security talk on insecure rails defaults. I was wondering if there is a way to tell if Rails now binds to ip 127.0.0.1, port 3000 by default? When I spin up rails s, I see
± |master {1} U:4 ✗| → rails s
=> Booting Puma
=> Rails 6.0.2.2 application starting in development
=> Run `rails server --help` for more startup options
/Users/pivotal/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.2/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/pivotal/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.2/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here
Puma starting in single mode...
* Version 4.3.3 (ruby 2.7.0-p0), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://**127.0.0.1**:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop
As per this pretty old Stack overflow post, I tried adding the following to my boot.rb and got an error about my Spring versions.
Boot.rb
require 'rails/commands/server'
module Rails
class Server
def default_options
super.merge({Port: 10524, Host: '127.0.0.1'})
end
end
end
± |master {1} U:4 ✗| → rails s
You've tried to invoke Spring when it's already loaded (i.e. the Spring constant is defined).
This is probably because you generated binstubs with Spring 1.0, and you now have a Spring version > 1.0 on your system. To solve this, upgrade your bundle to the latest Spring version and then run `bundle exec spring binstub --all` to regenerate your binstubs. This is a one-time step necessary to upgrade from 1.0 to 1.1.
I do those steps, but still an error.
You are using Rails 6, and latest versions uses puma so does your app. If you want to change the port open config/puma.rb. There you will see the line
port ENV.fetch("PORT") { 3000 }
This line is what makes rails start in port 3000. Change it to any other port. In your case -
port ENV.fetch("PORT") { 10524 }
Also if you want to change the bind address replace port with bind
#port ENV.fetch("PORT") { 3000 }
bind 'tcp://192.168.0.1:10524'
Check https://github.com/puma/puma for more.
I am working on a project which is an updated version of a new project. Using vagrant to load virtual environment and when i run
RAILS_ENV=development bundle exec rails s
The following is returned:
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.3-p222), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
When i visit the browser I have tried localhost:3000 and 127.0.0.1:3000 but keep getting:
ERR_CONNECTION_REFUSED
On the previous version of this project on a different repository loaded it was accessible via these URL's. This project has been updated to Rails 5 but dont know why it is listening on TCP rather than HTTP. Any suggestions?
As it has been already suggested, make sure that the server is bounden to 0.0.0.0 so that all interfaces can access it.
You might try:
RAILS_ENV=development bundle exec rails s -b 0.0.0.0
I am going through the rails tutorial. I am on chapter 1, section 1.3.2.
https://www.railstutorial.org/book/beginning#sec-the_hello_application
After I ran the command
rails server -b $IP -p $PORT
I see the following:
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://0.0.0.0:8080
=> Run rails server -h for more startup options
Puma starting in single mode...
Version 3.4.0 (ruby 2.3.0-p0), codename: Owl Bowl Brawl
Min threads: 5, max threads: 5
Environment: development
Listening on tcp://0.0.0.0:8080
Use Ctrl-C to stop
The terminal says it is running on http://0.0.0.0:8080, but when I visit this URL I get the follow error:
ERR_ADDRESS_INVALID
I am completely new to Rails. What can I do to solve this?
Do not try to access the project through the IP address and port number rails returns to you--it won't work!
Try rails server -b $IP -p $PORT
For further clarification check this link
The app will be running on http://[your_workspacename]-[your_username].c9users.io