Home Blog Services About Contact

Running Rails with SSL in the Development Environment

📅
✍️ BCKPCKR Team
Running Rails with SSL in the Development Environment
#rails #ssl #development #https #puma

When working on Rails applications, it can be useful to run your development server over HTTPS. This allows you to test features like secure cookies, service workers, and third-party integrations that require SSL. In the config/environments/development.rb file, Rails is configured to accept requests from a custom domain by appending it to the config.hosts list:

Rails.application.configure do
  config.hosts << ".example.com"
end

Next, the config/puma.rb file is updated to enable SSL:

ssl_bind "0.0.0.0", "8443", {
  key: "server.key",
  cert: "server.crt"
}

By binding Puma to port 8443 and providing certificate and key files, the Rails server will respond over HTTPS locally. You can generate the certificates with tools such as Certbot. Once you have your certificate files, place them in your Rails application root directory or update the paths in the Puma configuration accordingly. Once the server is running, you may want to expose it remotely for testing. An SSH reverse tunnel can forward the local SSL port to a remote server:

ssh -R 8443:localhost:8443 -N user@example.com

With this setup you can work securely with HTTPS in your development environment, test against real-world conditions, and share your development server over a secure tunnel when needed. This configuration is especially valuable when developing applications that integrate with services requiring SSL or when testing browser features that only work over HTTPS.