2012-05-14 33 views

回答

-1

只需在您的環境配置中使用config.force_ssl = true即可。

# config/application.rb 
module MyApp 
    class Application < Rails::Application 
    config.force_ssl = true 
    end 
end 

您還可以選擇性地啓用https,具體取決於當前的Rails環境。例如,您可能希望在開發時關閉HTTPS,並在分段/生產中啓用它。

# config/application.rb 
module MyApp 
    class Application < Rails::Application 
    config.force_ssl = false 
    end 
end 

# config/environments/production.rb 
MyApp::Application.configure do 
    config.force_ssl = true 
end 

在幕後,Rails添加的真棒機架:: SSL Rack中間件到應用程序中間件堆棧。 Rack :: SSL自動過濾請求,將非HTTPS請求重定向到相應的HTTPS路徑並應用一些額外的改進,以確保您的HTTPS請求是安全的。

+0

@mzjn感謝您的評論。我剛剛更新了相應的答案。保持良好的工作。 –