所以我有一個簡單的網站西納特拉:「錯誤壞URI」試圖獲取時的WEBrick接受HTTPS
# app.rb
require 'sinatra'
get '/' do
'Hello world!'
end
而且我可以設置的機架服務它通過HTTP:
# config.ru
require './app'
run Sinatra::Application
# vim: ft=ruby
當我瀏覽到http://localhost:9292
它工作正常:
% rackup
[2013-01-22 10:27:52] INFO WEBrick 1.3.1
[2013-01-22 10:27:52] INFO ruby 1.9.2 (2011-02-18) [x86_64-darwin10.7.4]
[2013-01-22 10:27:52] INFO WEBrick::HTTPServer#start: pid=7525 port=9292
127.0.0.1 - - [22/Jan/2013 10:28:05] "GET/HTTP/1.1" 200 12 0.0177
127.0.0.1 - - [22/Jan/2013 10:28:06] "GET /favicon.ico HTTP/1.1" 404 447 0.0007
我已經generated a self-signed certificate,經過一番去擠眉弄眼,還以爲我找到a way of setting up my rack file to use the cert and serve HTTPS:
# config.ru
require './app'
require 'webrick'
Rack::Server.start(
:Port => 9292,
:Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG),
:app => Sinatra::Application,
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(File.read "server.key"),
:SSLCertificate => OpenSSL::X509::Certificate.new(File.read "server.crt"),
:SSLCertName => [["CN", WEBrick::Utils::getservername]]
)
# vim: ft=ruby
但是,當我訪問https://localhost:9292
我得到Error code: ssl_error_rx_record_too_long
和WEBrick是使用...不高興:
% rackup
[2013-01-22 10:46:28] DEBUG TCPServer.new(0.0.0.0, 9292)
[2013-01-22 10:46:28] DEBUG TCPServer.new(::, 9292)
[2013-01-22 10:46:28] DEBUG Rack::Handler::WEBrick is mounted on /.
[2013-01-22 10:46:28] INFO WEBrick::HTTPServer#start: pid=7660 port=9292
[2013-01-22 10:46:33] DEBUG accept: 127.0.0.1:62185
[2013-01-22 10:46:33] ERROR bad URI `?w~Rx03I?\x06?\x00\x00H\x00??'.
localhost - - [22/Jan/2013:10:46:33 EST] "\x16\x03\x01\x00?\x01\x00\x00?\x03\x01P??Y?KOƛ\x0Ew/yO;P\x1E\x13 ?w~Rx03I?\x06?\x00\x00H\x00??" 400 316
- -> ?w~Rx03I?\x06?\x00\x00H\x00??
[2013-01-22 10:46:33] DEBUG close: 127.0.0.1:62185
隨意自己嘗試一下,所有的文件,你需要運行它(config.ru,app.rb,server.crt,server.key)在this gist。
所以我顯然做錯了什麼。我該如何解決它?
我以前也試過,我放棄了。我會很感興趣,看看你是否能找到一種方法來實現它! – iain