Skip to content

Instantly share code, notes, and snippets.

@blueplanet
Created November 22, 2016 01:04
Show Gist options
  • Save blueplanet/60b1f1a20d7e7ad47d7e5e65771029f3 to your computer and use it in GitHub Desktop.
Save blueplanet/60b1f1a20d7e7ad47d7e5e65771029f3 to your computer and use it in GitHub Desktop.
Heroku で Let's Encrypt 無料証明書を使う(自動更新あり) ref: http://qiita.com/blueplanet/items/b85634a0ced219e9ebe7
gem 'platform-api', github: 'jalada/platform-api', branch: 'master'
gem 'letsencrypt-rails-heroku', group: 'production'
$ heroku plugins:install heroku-cli-oauth
$ heroku authorizations:create -d "LetsEncrypt"
Created OAuth authorization.
ID: <heroku-client-id>
Description: LetsEncrypt
Scope: global
Token: <heroku-token>
heroku config:add ACME_DOMAIN=example.com,www.example.com [email protected] HEROKU_APP=you_app_name HEROKU_TOKEN=上記で作成したtoken
heroku run rake letsencrypt:renew
# 毎月の1日が更新する
if [ "$(date +%d)" = 01 ]; then rake letsencrypt:renew; fi
# application_controller.rb に追加
force_ssl if: :force_ssl?
private
def force_ssl?
not request.path =~ /^.well-known\/acme-challenge/
end
# config/environments/production.rb
config.force_ssl = true
config.ssl_options = { redirect: { exclude: -> request { request.path =~ /^.well-known\/acme-challenge/ } } }
Rails.application.configure do
...
config.middleware.use Letsencrypt::Middleware
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment