“错误的错误URI”当试图让WEBrick接受HTTPS时 [英] "Error bad URI" when trying to get WEBrick to accept HTTPS

查看:197
本文介绍了“错误的错误URI”当试图让WEBrick接受HTTPS时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个简单的Sinatra网站:

So I've got a simple Sinatra site:

# app.rb         
require 'sinatra'

get '/' do       
  'Hello world!' 
end              

我可以设置机架通过HTTP服务:

And I can set up rack to serve it over HTTP:

# config.ru              
require './app'          
run Sinatra::Application 

# vim: ft=ruby           

当我浏览 http:// localhost:9292 时,它工作正常:

And it works fine when I browse to 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

生成了一个自签名证书,经过一些谷歌搜索后,我发现设置机架文件以使用证书并提供HTTPS的方式

I've generated a self-signed certificate, and after some googling, thought I found 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 我得到错误代码:ssl_error_rx_record_too_long 和webrick是......不开心:

But when I visit https://localhost:9292 I get Error code: ssl_error_rx_record_too_long and webrick is ... unhappy:

% 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)都在这个要点

Feel free to try it yourself, all the files you need to run it (config.ru, app.rb, server.crt, server.key) are in this gist.

所以我显然做错了什么。我该如何解决?

So I'm obviously doing something wrong. How can I fix it?

推荐答案

你需要添加

require "webrick/https"

使其正常工作

这篇关于“错误的错误URI”当试图让WEBrick接受HTTPS时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆