self signed ssl certificate update localhost rails

To update a self-signed SSL certificate for localhost in Ruby on Rails, you can follow these steps:

  1. Generate a new self-signed SSL certificate:
  2. Open your terminal and navigate to your Rails application's root directory.
  3. Run the following command to generate a new self-signed SSL certificate: openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout config/ssl.key -out config/ssl.crt
  4. This command generates a new private key (ssl.key) and a self-signed SSL certificate (ssl.crt) valid for 365 days.

  5. Configure your Rails application to use the new SSL certificate:

  6. Open the config/environments/development.rb file in your Rails application.
  7. Uncomment or add the following lines to enable SSL in development mode: ruby config.force_ssl = true config.ssl_options = { redirect: { exclude: ->(request) { request.path =~ /health_check/ } } }
  8. Save the file and close it.

  9. Restart your Rails application:

  10. In your terminal, stop the Rails server if it is currently running by pressing Ctrl + C.
  11. Start the Rails server again by running the command rails s.

  12. Trust the new SSL certificate:

  13. Open your browser and visit https://localhost:3000.
  14. You may see a security warning because the certificate is self-signed. Proceed to trust the certificate and access your Rails application.

By following these steps, you will have successfully updated the self-signed SSL certificate for localhost in your Ruby on Rails application. This will allow you to securely access your application using HTTPS.