Skip to content

Instantly share code, notes, and snippets.

@goldeneggg

goldeneggg/sslrails

Created Jul 4, 2016
Embed
What would you like to do?
ローカルのrailsをオレオレ証明書でSSL化して起動する `sslrails` コマンド
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rubygems'
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
require 'webrick/ssl'
module Rails
class Server < ::Rack::Server
def default_options
# keyとcertは自前で事前準備しておくか、起動時に生成するか
# (このスクリプトでは後者)
cn = [[ "CN", WEBrick::Utils::getservername]]
comment = "Generated by Ruby/OpenSSL"
cert, rsa = WEBrick::Utils::create_self_signed_cert(1024, cn, comment)
ssl_private_key = rsa.to_s
ssl_certificate = cert.to_s
super.merge(
{
:Port => 3000, # ポートは変えたきゃ変える。ここで上書きしなければデフォルトの 9292
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(ssl_private_key),
:SSLCertificate => OpenSSL::X509::Certificate.new(ssl_certificate),
:SSLCertName => cn
}
)
end
end
end
require 'rails/commands'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.