Sinatra 应用程序,Ubuntu 12
#config.ru
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("/etc/ssl/certs/ssl-cert-snakeoil.pem").read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("/etc/ssl/private/ssl-cert-snakeoil.key").read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ]
}
Rack::Handler::WEBrick.run app, webrick_options
然后我运行它
sudo rackup
它运行并且似乎没问题:
[2012-11-06 16:10:14] INFO WEBrick 1.3.1
[2012-11-06 16:10:14] INFO ruby 1.9.3 (2012-04-20) [x86_64-linux]
[2012-11-06 16:10:14] DEBUG TCPServer.new(0.0.0.0, 8443)
[2012-11-06 16:10:14] DEBUG TCPServer.new(::, 8443)
.......
但是当我去http://localhost:8443/app1
我得到
[2012-11-06 17:07:25] ERROR OpenSSL::SSL::SSLError: SSL_accept returned=1 errno=0 state=unknown state: http request
/usr/lib/ruby/1.9.1/openssl/ssl-internal.rb:164:in `accept'
[2012-11-06 17:07:25] ERROR OpenSSL::SSL::SSLError: SSL_accept returned=1 errno=0 state=unknown state: http request
/usr/lib/ruby/1.9.1/openssl/ssl-internal.rb:164:in `accept'
[2012-11-06 17:07:25] ERROR OpenSSL::SSL::SSLError: SSL_accept returned=1 errno=0 state=unknown state: http request
/usr/lib/ruby/1.9.1/openssl/ssl-internal.rb:164:in `accept'
以及页面中的“此网页不可用”标签。
我究竟做错了什么?