我一直在尝试将 webrick 配置为在我的应用程序的所有页面上使用 SSL。
我添加了
gem 'rack-ssl', :require => 'rack/ssl'
到我的 gem 文件和
config.middleware.insert_before ActionDispatch::Static, "Rack::SSL"
config.force_ssl = true
到我的 /config/application.rb 文件。我将 webrick 配置为使用我的自签名证书,方法是修改我的 /script/rails 文件看起来像这样
require 'rubygems'
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
:Port => 3001,
: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_PEER,
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("home/sureweb/rubystuff/server.cert.key").read),
:SSLCertificate => OpenSSL::X509::Certificate.new(File.open("home/sureweb/rubystuff/server.cert.crt").read),
:SSLCACertificateFile => 'home/sureweb/rubystuff/server.crt',
:SSLCertName => [["CN", WEBrick::Utils::getservername]]
})
end
end
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
但是每次我运行 rails s 我都会收到一条消息说
You have already activated activesupport 3.2.3, but your Gemfile requires activesupport 3.0.12. Using bundle exec may solve this. (Gem::LoadError)
通常我可以通过删除版本 3.2.3 来解决这个问题,但是我有许多其他依赖它的 gem,所以这不是一个选择。还有另一种方法可以让这个工作吗?