Posts

Rails: Using SSL in locale development

Mittwoch, 29. Juli 2020, 12:40 Uhr | roberto@vasquez-angel.de |

  1. Generate a new certificate:
  
    # Create a folder to store the certificates
    mkdir config/certs
    # Ignore the certificates folder to avoid accidentally commiting the certs to the repo
    echo "config/certs/*" >> .gitignore
    # generate the certificate:
    # Be sure to set the domain name to "lvh.me". Other settings don't matter
    openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout config/certs/lvh.me.key -out config/certs/lvh.me.crt
  
  1. Configure rails to optionally force ssl in development mode:
  
    Rails.application.configure do
      config.force_ssl = true if ENV.fetch('SSL', nil) == "true"
    end
  
  1. Start the server in SSL mode:
  
    SSL=true bundle exec rails s -b 'ssl://0.0.0.0:3000?key=./config/certs/lvh.me.key&cert=./config/certs/lvh.me.crt'
  
  1. Access the page:
  
    https://lvh.me:3000/
  
If you get following error message in the puma logs when accessing the page with Chrome:
  
    SSL error, peer: 127.0.0.1, peer cert: , #<Puma::MiniSSL::SSLError: OpenSSL error: error:141F7065:SSL routines:final_key_share:no suitable key share - 337604709>
  
Make sure to use puma '>= 4'.