0

我正在使用一个名为 Radiant(版本 0.9.1)、Rails 2.3.18 和 Ruby 1.8.7 的 CMS。我必须让这个 gem 中的路线使用“https”。我需要这样做,即我不会编辑 gem 源文件本身,而是在扩展中覆盖 gem 的路由。我该怎么做呢?

4

1 回答 1

0

服务器的配置实际上取决于您的服务器堆栈的样子

要将您的 Rails 应用程序配置为使用 SSL,您需要强制使用 ssl

在您的 config/environments/production.rb 中:

config.force_ssl = true

要在本地测试 ssl,我建议尝试将瘦作为网络服务器(也将 config.force_ssl 放在 development.rb 中进行测试)

添加:

gem 'thin' 

到您的 gemfile 并启动一个瘦 ssl 服务器:

$ thin start --ssl -p 3000

编辑导轨 2:

对于 Rails 2,这应该有效:

库/force_ssl.rb

class ForceSSL
  def initialize(app)
    @app = app
  end

  def call(env)
    if env['HTTPS'] == 'on' || env['HTTP_X_FORWARDED_PROTO'] == 'https'
      @app.call(env)
    else
      req = Rack::Request.new(env)
      [301, { "Location" => req.url.gsub(/^http:/, "https:") }, []]
    end
  end
end

配置/生产.rb

config.middleware.use "ForceSSL"

配置/应用程序.rb

require File.expand_path('../../lib/force_ssl.rb', __FILE__)

来源:在 Rails 2 应用程序中使用 ssl_requirement 强制 SSL

于 2015-12-15T08:55:04.177 回答