Use SSL in Rails local development with Puma
Having a Rails local development environment with SSL/HTTPS support can be very handy. You can work with payment plaforms APIs, like Stripe or Apple Pay, without having to resort to tools like ngrok and you can increase development/production parity.
Puma configuration
You can configure Puma to use SSL only in development environment with a
config/puma.rb
file like this:
SSL certificates
To easily generate a self-signed and locally-trusted development SSL certificate for your Rails application, you can use mkcert.
Create and install a local Certification Authority:
mkcert -install
Create corresponding certificate and key files in the config/certs
directory:
mkdir -p config/certs
mkcert -cert-file config/certs/localhost.pem -key-file config/certs/localhost-key.pem localhost
You can use mkcert to install the same development CA you’ve created on any other development box.
Copy the CA certificate to your application:
cp "$(mkcert -CAROOT)/rootCA.pem" config/certs
Install the same CA on another machine (you can add this step to your bin/setup
script):
CAROOT=config/certs mkcert -install