1
0

開発環境のpumaでhttps接続をを有効にする

Posted at

はじめに

開発環境のpumaを自己署名証明書でhttps対応させます。任意のFQDNでアクセスし、証明書はブラウザ側で例外指定する想定です。

環境

  • AlmaLinux 9.3
  • Ruby 2.7.8
  • Rails 6.1.4.7
  • puma 5.5.2

自己署名証明書の作成

$ cd /path/to/app
$ mkdir -p config/ssl && pushd $_
$ openssl req -x509 \
              -newkey rsa:4096 \
              -keyout server.key \
              -out server.crt \
              -days 3650 \
              -noenc \
              -subj '/CN=dev.example.com' \
              -extensions san \
              -config <( \
                echo '[ req ]'; \
                echo 'distinguished_name=req'; \
                echo '[ san ]'; \
                echo 'subjectAltName=DNS.1:dev.example.com';)
$ chmod 400 server.*
$ popd

アプリの config/ssl ディレクトリに鍵とCertを生成しています。最近のブラウザはCNだけでなくExtensionsセクションのDNS情報もチェックするため、そちらも記載しています。

dev.example.comを任意のFQDNに置き換えてください。

pumaの起動設定

config/puma.rb
ssl_bind '0.0.0.0', '3443', {
  key: 'config/ssl/server.key',
  cert: 'config/ssl/server.crt',
  verify_mode: 'none'
}

pumaの起動

$ bundle exec pumactl start

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0