0
0

Railsのローカル環境にHTTPSとカスタムドメインを導入!10分でOK!

Last updated at Posted at 2023-10-10

はじめに

ローカル認証局(CA)の機能を提供するmkcertを使用して、MacOSのローカル環境でHTTPSとカスタムドメインを導入してみましょう!

mkcertの設置

brewを利用してパソコンにmkcertを設置します。

brew install mkcert

認証局(CA)の設置

mkcertのコマンドを利用してMacOSにローカル認証局(CA)のルート証明書を設置します。

mkcert -install

SSL証明書

config/ssl ディレクトリにSSL証明書とプライベートキーを生成します。

# Railsプロジェクトのルートディレクトリで実行
mkdir -p config/ssl && cd $_ && mkcert "*.custom_domain.localhost"

Rails環境構成の変更

config/environments/development.rb ファイルにカスタムドメインを追加します。

# config/environments/development.rb
config.force_ssl = true
config.hosts << '.custom_domain.localhost'

Railsアプリの実行

ローカルでSSL証明書とプライベートキーを利用してRailsアプリを実行します。

rails server -b 'ssl://0.0.0.0:3443?key=config/ssl/_wildcard.custom_domain.localhost-key.pem&cert=config/ssl/_wildcard.custom_domain.localhost.pem'

参考文献

0
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
0
0