title: Sinatra on Ubuntu 12 - SSL error
body: <p>Sinatra application, Ubuntu 12</p>
  
  <pre><code>#config.ru
  require 'sinatra/base'
  require 'openssl'
  require 'webrick'
  require 'webrick/https'
  
  class App1 &lt; Sinatra::Base
    get '/' do
      'app1'
    end
  end
  
  class App2 &lt; 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               =&gt; 8443,
    :Logger             =&gt; WEBrick::Log::new($stdout, WEBrick::Log::DEBUG),
    :DocumentRoot       =&gt; "./public",
    :SSLEnable          =&gt; true,
    :SSLCertificate     =&gt; OpenSSL::X509::Certificate.new(  File.open("/etc/ssl/certs/ssl-cert-snakeoil.pem").read),
    :SSLPrivateKey      =&gt; OpenSSL::PKey::RSA.new(          File.open("/etc/ssl/private/ssl-cert-snakeoil.key").read),
    :SSLCertName        =&gt; [ [ "CN",WEBrick::Utils::getservername ] ]
  }
  
  Rack::Handler::WEBrick.run app, webrick_options
  </code></pre>
  
  <p>Then I run it</p>
  
  <pre><code>sudo rackup
  </code></pre>
  
  <p>it runs and it seems to be ok:</p>
  
  <pre><code>[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)
  .......
  </code></pre>
  
  <p>but when I go to <code>http://localhost:8443/app1</code> I get</p>
  
  <pre><code>[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'
  </code></pre>
  
  <p>and the label "This web page is not available" in the page.</p>
  
  <p>What am I doing wrong?</p>