Advertisement
Guest User

How to make Sinatra work over HTTPS/SSL

a guest
Feb 25th, 2012
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. require 'sinatra/base'
  2. require 'webrick'
  3. require 'webrick/https'
  4. require 'openssl'
  5.  
  6. CERT_PATH = '/opt/myCA/server/'
  7.  
  8. webrick_options = {
  9. :Port => 8443,
  10. :Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG),
  11. :DocumentRoot => "/ruby/htdocs",
  12. :SSLEnable => true,
  13. :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
  14. :SSLCertificate => OpenSSL::X509::Certificate.new( File.open(File.join(CERT_PATH, "my-server.crt")).read),
  15. :SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open(File.join(CERT_PATH, "my-server.key")).read),
  16. :SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ]
  17. }
  18.  
  19. class MyServer < Sinatra::Base
  20. post '/' do
  21. "Hellow, world!"
  22. end
  23. end
  24.  
  25. Rack::Handler::WEBrick.run MyServer, webrick_options
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement