Last active
January 14, 2021 00:47
-
-
Save k-ta-yamada/6d3d6c75980dee5cf1dd189e170badce to your computer and use it in GitHub Desktop.
Sinatra + WEBrick + HTTPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'webrick/https' | |
set :server_settings, | |
SSLEnable: true, | |
SSLCertName: [['CN', WEBrick::Utils.getservername]] | |
get '/' do | |
'https page' | |
end |
https://github.com/ruby/ruby/blob/202bbda2bf5f25343e286099140fb9282880ecba/lib/webrick.rb#L88-L121
# == HTTPS
#
# To create an HTTPS server you only need to enable SSL and provide an SSL
# certificate name:
#
# require 'webrick'
# require 'webrick/https'
#
# cert_name = [
# %w[CN localhost],
# ]
#
# server = WEBrick::HTTPServer.new(:Port => 8000,
# :SSLEnable => true,
# :SSLCertName => cert_name)
#
# This will start the server with a self-generated self-signed certificate.
# The certificate will be changed every time the server is restarted.
#
# To create a server with a pre-determined key and certificate you can provide
# them:
#
# require 'webrick'
# require 'webrick/https'
# require 'openssl'
#
# cert = OpenSSL::X509::Certificate.new File.read '/path/to/cert.pem'
# pkey = OpenSSL::PKey::RSA.new File.read '/path/to/pkey.pem'
#
# server = WEBrick::HTTPServer.new(:Port => 8000,
# :SSLEnable => true,
# :SSLCertificate => cert,
# :SSLPrivateKey => pkey)
#
Sinatra(WEBrick)でsslサーバをたてる
https://gist.github.com/suruseas/3489236
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/ruby/ruby/blob/trunk/lib/webrick/ssl.rb#L20-L22