Skip to content

Instantly share code, notes, and snippets.

@hieuns
Created February 5, 2020 06:48
Show Gist options
  • Save hieuns/77543331c6b97fc55fdb8e3a5d509e73 to your computer and use it in GitHub Desktop.
Save hieuns/77543331c6b97fc55fdb8e3a5d509e73 to your computer and use it in GitHub Desktop.
Run rails server in development environment with SSL

Sources:

  1. Create self-signed SSL certificate
cd
mkdir .ssl
cd .ssl

# enter localhost.ssl as Common Name
openssl req -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout localhost.key -out localhost.crt
  1. Add localhost.ssl to /etc/hosts
echo "127.0.0.1 localhost.ssl" | sudo tee -a /etc/hosts
  1. Modify config of Rails app
# config/environments/development.rb

config.force_ssl = true

# show server log like running server with 'rails s' command
logger           = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger    = ActiveSupport::TaggedLogging.new(logger)
  1. Run server
thin start -p 3000 --ssl --ssl-key-file ~/.ssl/localhost.key --ssl-cert-file ~/.ssl/localhost.crt
  1. Access web app with https protocol

Open browser and access https://localhost.ssl:3000/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment