开发者

"config.force_ssl = true" not forcing HTTPS

开发者 https://www.devze.com 2023-04-13 04:20 出处:网络
I am running Rails 3.1 and have tried putting the above line in development.rb and application .rb (not both at the s开发者_运维问答ame time) but it doesn\'t seem to do anything. My request are still

I am running Rails 3.1 and have tried putting the above line in development.rb and application .rb (not both at the s开发者_运维问答ame time) but it doesn't seem to do anything. My request are still working on HTTP. Isn't this meant to force all requests to use HTTPS? I'm sure I've missed something very obvious here but can't for the life of me think of what - being a newbie doesn't help either.

Any help would be greatly appreciated.

Cheers, Dany.


It wont work locally, have you deployed it?


It will work provided that your local server (webrick?) is configured to use SSL, below is one way to do that via script/rails:

#!/usr/bin/env ruby.exe
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

# 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 => 3000,
                :SSLEnable => false, # set to true to automatically generate SSL cert
                :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
                #:SSLCertificate => OpenSSL::X509::Certificate.new(File.open("ssl.crt").read),
                :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'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号