Skip to content

Instantly share code, notes, and snippets.

@goldeneggg
Created July 4, 2016 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldeneggg/a69a7fb2699bdb54041c8a9a5ef0ee90 to your computer and use it in GitHub Desktop.
Save goldeneggg/a69a7fb2699bdb54041c8a9a5ef0ee90 to your computer and use it in GitHub Desktop.
ローカルの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