新手问题 Cant run rails app locally after adding SSL for production

color_huo · September 17, 2013 · Last by allenwei replied at September 18, 2013 · 2473 hits

在 production.rb 里加了这条 config.force_ssl = true 后,本地 rails s 就不行了

stackoverflow 上找了几个解决方法,都是直接把 WEBrick 换掉 像换成 thin, thin start --ssl 或者换成 pow To add POW to your app run this command curl get.pow.cx | sh and then cd ~/.pow followed by ln -s /path/to/myapp.

有没有其他解决方法?

用 Nginx?记得 RailsCasts 里面有一期是讲 SSL 的

从别地儿搬过来的你试试,实在不行就得上 Nginx 了,也不麻烦

require 'sinatra/base'
require 'openssl'
require 'webrick'
require 'webrick/https'

class App1 < Sinatra::Base
  get '/' do
    'app1'
  end
end

class App2 < Sinatra::Base
  get '/' do
    'app2'
  end
end

app = Rack::Builder.new do 
  map '/app1' do
    run App1
  end
  map '/app2' do
    run App2
  end
end

webrick_options = {
  :Port               => 8443,
  :Logger             => WEBrick::Log::new($stdout, WEBrick::Log::DEBUG),
  :DocumentRoot       => "./public",
  :SSLEnable          => true,
  :SSLCertificate     => OpenSSL::X509::Certificate.new(  File.open("./ssl.pem").read),
  :SSLPrivateKey      => OpenSSL::PKey::RSA.new(          File.open("./ssl.key").read),
  :SSLCertName        => [ [ "CN",WEBrick::Utils::getservername ] ]
}

Rack::Handler::WEBrick.run app, webrick_options

https://gist.github.com/carlhoerberg/1685064

You need to Sign in before reply, if you don't have an account, please Sign up first.