Skip to content

Instantly share code, notes, and snippets.

@carlhoerberg
Created January 26, 2012 20:55
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save carlhoerberg/1685064 to your computer and use it in GitHub Desktop.
Save carlhoerberg/1685064 to your computer and use it in GitHub Desktop.
Webrick ssl example
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment