Search code examples
ruby-on-railsproduction-environment

Rails redirects to https on localhost, don't know why


In development environment everything is fine.

But when I start with rails s --environment=production

I get this:

=> Booting WEBrick
=> Rails 3.2.18 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2014-06-18 23:09:16] INFO  WEBrick 1.3.1
[2014-06-18 23:09:16] INFO  ruby 1.9.3 (2013-11-22) [x86_64-linux]
[2014-06-18 23:09:16] INFO  WEBrick::HTTPServer#start: pid=6649 port=3000

And the server appears to be working.

But when I go to localhost:3000 it changes to https:localhost and browser shows Unable to connect.

In production.log there is no error.

Thanks!

EDIT: After searching for ssl with grep I get:

./app/controllers/import_controller.rb:    http.use_ssl = true 
./app/models/user_contact.rb:    http.use_ssl = true 
./app/views/layouts/better_iceland.html.haml:        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
./app/views/layouts/yrpri_front.html.haml:        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
./app/views/layouts/estartup.html.haml:        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
./app/views/shared/_analytics.html.haml:    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
./config/environments/production.rb~:#    method = request.ssl? ? "https" : "http"
./config/environments/production.rb~:  config.force_ssl = true
./config/environments/production.rb:#    method = request.ssl? ? "https" : "http"
./config/environments/production.rb:  config.force_ssl = true
./config/newrelic.yml:  ssl: false
./config/application.rb:    # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
./config/locales/sv-SE.yml:  d7c8c85bf79bbe1b7188497c32c3b0ca: Misslyckades
./agpl-3.0.txt:  You may not propagate or modify a covered work except as expressly
./Gemfile.lock:    rack-ssl (1.3.4)
./Gemfile.lock:      rack-ssl (~> 1.3.2)
./lib/contacts/contacts/windows_live.rb:      http.use_ssl = true

I changed in production.rb config.force_ssl = true to false But it still gets redirected (I restarted the server).


Solution

  • Do you have the following set in your config?

    # config/application.rb
    module MyApp
      class Application < Rails::Application
        config.force_ssl = true
      end
    end