In my project, I just want to make my every request will be done through SSL. how to acheive this? I mean how to add SSL to Rails App?
I tried adding
config.force_ssl = true
to application.rb. but It showing me an error like this.
Invalid request: Invalid HTTP format, parsing fails.
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/thin-1.6.1/lib/thin/request.rb:84:in `execute'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/thin-1.6.1/lib/thin/request.rb:84:in `parse'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/thin-1.6.1/lib/thin/connection.rb:41:in `receive_data'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/thin-1.6.1/lib/thin/backends/base.rb:73:in `start'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/thin-1.6.1/lib/thin/server.rb:162:in `start'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.5.2/lib/rack/handler/thin.rb:16:in `run'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.2/lib/rails/commands/server.rb:84:in `start'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.2/lib/rails/commands.rb:76:in `block in <top (required)>'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
/home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
First you need to set ssl certificate to your Application. For example, if you're using nginx, then you need to make something like this nginx config
Use a filter in application_controller.rb or use some gem
class ApplicationController < ActionController::Base
before_filter :redirect_to_https
def redirect_to_https
redirect_to :protocol => "https://" unless request.ssl?
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With