“config.force_ssl = true”不强制使用 HTTPS

发布于 2024-12-10 18:33:26 字数 202 浏览 0 评论 0原文

我正在运行 Rails 3.1 并尝试将上述行放入development.rb 和 application.rb (不是同时),但它似乎没有做任何事情。我的请求仍在 HTTP 上运行。这不是意味着强制所有请求都使用 HTTPS 吗?我确信我在这里错过了一些非常明显的东西,但我一生都无法想到什么 - 作为新手也无济于事。

任何帮助将不胜感激。

干杯, 丹妮.

I am running Rails 3.1 and have tried putting the above line in development.rb and application .rb (not both at the same 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫林﹌晚霞¤ 2024-12-17 18:33:26

本地不行,你部署了吗?

It wont work locally, have you deployed it?

不如归去 2024-12-17 18:33:26

只要您的本地服务器(webrick?)配置为使用 SSL,它就会工作,下面是通过 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'

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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文