Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running rails server with ssl? (puma)

I am currently using rails 5.2.1. When I start my rails server I do:

rails s -p 3000 -b x.x.x.x(ip) -e production -d

This will start the rails server which is using puma. Is there a way I can use SSL with my rails app?

like image 359
SWO Avatar asked Oct 30 '25 22:10

SWO


2 Answers

Don't expose Puma directly to the internet - puma is designed under the assumption that it will be behind a reverse proxy, such as nginx.

The nginx layer will provide your application with another layer or protection and has the added benefit of significantly speeding up any static files your application might serve (assets).

You can use SSL/TLS, using puma's -b option (try puma -help), but unless you have another option, I would avoid that.

Just to clarify, I'm the author of the iodine HTTP / WebSocket Ruby server, which also supports SSL/TLS... consider this advice as very informed: I recommend a reverse proxy.

like image 116
Myst Avatar answered Nov 02 '25 22:11

Myst


As long as you have the local keys somewhere in your config directory you should be able to do:

rails s puma -p 3000 -b 'ssl://0.0.0.0:3000?key=config/your_key_file.key&cert=config/your_certificate_file.crt'

If you need to know how to generate a local certificate and key this is a good post: https://rossta.net/blog/local-ssl-for-rails-5.html#create-a-self-signed-certificate

like image 33
NM Pennypacker Avatar answered Nov 02 '25 22:11

NM Pennypacker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!