How do you configure WEBrick to use SSL in Rails?

前端 未结 2 1990
情深已故
情深已故 2020-11-27 16:07

Prior to Rails 3, you could modify the script/server file to add in SSL parameters and tell the server command to use the HTTPS version of WEBrick. Now that all of those scr

2条回答
  •  日久生厌
    2020-11-27 16:50

    An Alternative to SSL/HTTPS on WEBrick: SSL/HTTPS on Thin

    As an alternative to trying to set up WEBrick to use HTTPS/SSL for your Rails app, you can try switching to using the Thin server instead, because it comes with convenient options for setting up HTTPS/SSL out-of-the-box.

    Installing Thin

    First, add Thin as a gem to your Gemfile:

    gem 'thin'
    

    Then run bundle install from the command line.

    Using Thin HTTPS/SSL for Development Environments

    If you just want to test your Rails app using HTTPS/SSL in your local development environment, then you simply run

    thin start --ssl
    

    I have to emphasize that this is not suitable for production environments, because you need to use a valid SSL certificate from a Certificate Authority in order for SSL/HTTPS connections to be verifiable and secure.

    Additional Options

    There are also other options that you can pass to Thin. You can get a full list of them by running thin --help. For example, I like to specify my own ip-address and port, as well as daemonizing Thin into a background process:

    thin start --ssl \
      --address  \
      --port  \
      --daemonize
    

    Using Thin HTTPS/SSL with an SSL Certificate

    If you want to tell Thin to use an SSL certificate (for example, one that you've obtained from a valid Certificate Authority), then you can use these options:

    thin start --ssl \
      --ssl-cert-file  \
      --ssl-key-file 
    

提交回复
热议问题