gpt4 book ai didi

ruby-on-rails - 无法在 Windows 10 的开发中使用 thin 设置 SSL

转载 作者:太空宇宙 更新时间:2023-11-03 14:50:52 28 4
gpt4 key购买 nike

我需要在我的开发环境中设置 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

开发.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

最佳答案

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

关于ruby-on-rails - 无法在 Windows 10 的开发中使用 thin 设置 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34485707/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com