我需要在我的開發環境中設置https
並且我已經用完了選項。我所有的嘗試都給出了同樣的錯誤,當我去https://localhost:3001
我很確定這個問題與eventmachine
有關,我發現this stackoverflow後,但我不知道如何應用它來測試它。如果任何人都可以幫助我,那將是驚人的。無法在Windows 10上使用瘦開發設置SSL
這是我已經試過:
我試過正常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並對windows進行了必要的更正。
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