在Windows 10上无法在开发中使用瘦设置SSL

时间:2015-12-27 22:52:25

标签: ruby-on-rails ruby-on-rails-4 ssl https thin

我需要在我的开发环境中设置https并且我已经用完了选项。当我去https://localhost:3001时,我所尝试的所有内容都会出现同样的错误我很确定问题与eventmachine有关,我找到了this stackoverflow帖子,但我不知道不知道如何应用它来测试它。如果有人能帮助我,这将是惊人的。

Using rack adapter
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on 0.0.0.0:3001, CTRL+C to stop
terminate called after throwing an instance of 'std::runtime_error'
  what():  Encryption not available on this event-machine

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

这是我尝试过的:

我尝试使用正常force_ssl

application.rb

class Application < Rails::Application
  config.force_ssl = false

development.rb

Rails.application.configure do
  config.force_ssl = true

application_controller.rb

force_ssl

/etc/hosts

127.0.0.1 localhost.ssl

然后我使用thin start -p 3000启动一台服务器,我尝试了thin start -p 3001 --ssl --ssl-key-file C:/.ssl/server.key --ssl-cert-file C:/.ssl/server.crt和常规thin start --ssl -p 3001当我转到https://localhost:3000时,我收到此错误(在终端中正在运行-p 3000):

Invalid request: Invalid HTTP format, parsing fails.
    C:/Ruby200/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/request.rb:84:in `execute'
    C:/Ruby200/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/request.rb:84:in `parse'
    C:/Ruby200/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/connection.rb:39:in `receive_data'
    C:/Ruby200/lib/ruby/gems/2.0.0/bundler/gems/eventmachine-076a526915dc/lib/eventmachine.rb:194:in `run_machine'
    C:/Ruby200/lib/ruby/gems/2.0.0/bundler/gems/eventmachine-076a526915dc/lib/eventmachine.rb:194:in `run'
    C:/Ruby200/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/backends/base.rb:73:in `start'
    C:/Ruby200/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/server.rb:162:in `start'
    C:/Ruby200/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/controllers/controller.rb:87:in `start'
    C:/Ruby200/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/runner.rb:200:in `run_command'
    C:/Ruby200/lib/ruby/gems/2.0.0/gems/thin-1.6.4/lib/thin/runner.rb:156:in `run!'
    C:/Ruby200/lib/ruby/gems/2.0.0/gems/thin-1.6.4/bin/thin:6:in `<top (required)>'
    C:/Ruby200/bin/thin:23:in `load'
    C:/Ruby200/bin/thin:23:in `<main>'

然后我跟着这个tutorial并对窗口做了必要的修正。

config/initializers/force_ssl_patch.rb

ActionController::ForceSSL::ClassMethods.module_eval do
  def force_ssl(options = {})
    config = Rails.application.config

    return unless config.use_ssl # <= this is new

    host = options.delete(:host)
    port = config.ssl_port if config.respond_to?(:ssl_port) && config.ssl_port.present? # <= this is also new

    before_filter(options) do
      if !request.ssl?# && !Rails.env.development? # commented out the exclusion of the development environment
        redirect_options = {:protocol => 'https://', :status => :moved_permanently}
        redirect_options.merge!(:host => host) if host
        redirect_options.merge!(:port => port) if port # <= this is also new
        redirect_options.merge!(:params => request.query_parameters)
        redirect_to redirect_options
      end
    end
  end
end

1 个答案:

答案 0 :(得分:0)

尝试使用OpenSSL支持重新编译EventMachine,如下所述:https://github.com/eventmachine/eventmachine/wiki/Building-EventMachine-with-SSL-on-Windows