Ruby on rails 我如何告诉Rails 4应用程序我的SSL证书在哪里?

Ruby on rails 我如何告诉Rails 4应用程序我的SSL证书在哪里?,ruby-on-rails,ruby-on-rails-4,ssl,Ruby On Rails,Ruby On Rails 4,Ssl,我试图告诉Rails 4应用程序在哪里可以找到SSL证书 Ww通过修改bin/rails,添加了 if ENV['SSL'] == "true" module Rails class Server < ::Rack::Server def default_options super.merge({ :Port => 443, :environment => (ENV['RAILS_ENV'] ||

我试图告诉Rails 4应用程序在哪里可以找到SSL证书

Ww通过修改
bin/rails
,添加了

if ENV['SSL'] == "true"
  module Rails
    class Server < ::Rack::Server
      def default_options
        super.merge({
          :Port => 443,
          :environment => (ENV['RAILS_ENV'] || "development").dup,
          :daemonize => false,
          :debugger => false,
          :pid => File.expand_path("tmp/pids/server.pid"),
          :config => File.expand_path("config.ru"),
          :SSLEnable => true,
          :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
          :SSLPrivateKey => OpenSSL::PKey::RSA.new(
                           File.open("/path/to/my/private/.key").read),
          :SSLCertificate => OpenSSL::X509::Certificate.new(
                           File.open("/path/to/my.cert").read),
          :SSLCertName => [["CN", WEBrick::Utils::getservername]],
        })
      end
    end
  end
end
if ENV['SSL']=“true”
模块导轨
类服务器<::机架::服务器
def default_选项
超级合并({
:端口=>443,
:environment=>(ENV['RAILS_ENV']| |“development”).dup,
:daemonize=>false,
:debugger=>false,
:pid=>File.expand_路径(“tmp/pids/server.pid”),
:config=>File.expand_path(“config.ru”),
:SSLEnable=>true,
:SSLVerifyClient=>OpenSSL::SSL::VERIFY\u NONE,
:SSLPrivateKey=>OpenSSL::PKey::RSA.new(
File.open(“/path/to/my/private/.key”).read),
:SSLCertificate=>OpenSSL::X509::Certificate.new(
打开(“/path/to/my.cert”).read),
:SSLCertName=>[[“CN”,WEBrick::Utils::getservername]],
})
结束
结束
结束
结束
所有这些都很好,但我希望这些设置放在我的
config/environments/staging.rb
文件中,并且我希望它不特定于Webbrick

  • 这是正确的方法吗
  • 如果是,如何将这些设置移动到
    config/environments/staging.rb

  • 评论的共识是:

  • 不,还有
  • 见1

  • 感谢@tpbowden和@josh deeden的快速响应。

    您可能应该使用反向代理(nginx或apache)来解密SSL,并将应用程序与SSL证书和密钥完全解耦。正如tpbowden所说,您希望使用nginx/apache反向代理终止SSL连接。在我构建Rails应用程序的10多年中,我从未在Rails中直接配置过SSL。使用诸如passenger之类的工具可能是您阻力最小的途径。好的,Nginx使用了Unicorn,而Webbrick使用了Unicorn。此外,如果您要部署到Heroku,您可能需要查看以下方便的教程: