2013-05-02 48 views
0

如何将www.example.com重定向到https://www.example.com在开发中,我如何使用自签名证书重定向到https?

我正在开发中,我正在使用自签名证书。我在application.rb中加入config.force_ssl = true和我的应用程序控制器添加了这种方法的before_filter回调:

def redirect_secure 
    redirect_to protocol: "https" if request.protocol == "http" 
end 
+0

的可能重复[你是如何处理的发展SSL?(http://stackoverflow.com/questions/2118685/how-do-you-handle-ssl-在开发中) – 2013-05-02 10:27:13

回答

1

对于服务器的SSL证书配置发展添加以下代码脚本/轨文件,

module Rails 
    class Server < ::Rack::Server 
     def default_options 
      super.merge({ 
       :Port => 3445, 
       :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("/home/mohanraj/myCA/server_key.pem").read), 
       :SSLCertificate => OpenSSL::X509::Certificate.new(
         File.open("/home/mohanraj/myCA/server_crt.pem").read), 
       :SSLCertName => [["CN", WEBrick::Utils::getservername]] 
      }) 
     end 
    end 
end 

注意:请为ssl​​文件提供正确的路径。

请点击此链接重定向http://www.railway.at/2013/02/12/using-ssl-in-your-local-rails-environment/

+0

感谢您的回答!我会试试这个。 – MoMo 2013-05-02 10:16:19

+0

Monkeypatching ActionController :: ForceSSL是解决这个问题的最后手段?我读过这篇文章:https://github.com/rails/rails/pull/5023,开发人员说,在任何环境下,默认情况下都不应禁用SSL。任何机会,任何人都知道这个请求是否有更新? – MoMo 2013-05-03 03:10:34