I need to set up https
in my development env and I've run out of options. Everything I have tried all give the same error when I go to https://localhost:3001
I'm fairly sure that the problem has something to do with eventmachine
and I found this stackoverflow post, but I don't know how to apply it to test it. If anyone can help me out that would be amazing.
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.
Here's what I've tried:
I tried the normal force_ssl
with:
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
Then I start one server with thin start -p 3000
and I've tried both thin start -p 3001 --ssl --ssl-key-file C:/.ssl/server.key --ssl-cert-file C:/.ssl/server.crt
and the regular thin start --ssl -p 3001
When I go to https://localhost:3000
I get this error (in terminal that's running -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>'
Then I followed this tutorial and made the necessary corrections for 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