Help us understand the problem. What is going on with this article?

Rails + Puma + React のローカル環境で HTTPS 接続してみる

More than 1 year has passed since last update.

概要

Rails + Puma + React のローカル開発環境でどうしても HTTPS 接続したいときがあったので、ローカル環境で HTTPS 接続するための手順を残します。

手順

1. 自己証明書作成

プロジェクトディレクトリで下記コマンドを実行する。

$ cd /Users/owner/git/hoge
$ openssl genrsa -out ./localhost.key 2048
$ sudo openssl req -new -x509 -key ./localhost.key -out ./localhost.crt -days 3650 -subj /CN=localhost

2. Puma 設定ファイル編集

config/puma.rb
# HTTPS 利用可能設定
if "development" == ENV.fetch("RAILS_ENV") { "development" }
  ssl_bind '0.0.0.0', '3001', {
    key: "/Users/owner/git/hoge/server.key",
    cert: "/Users/owner/git/hoge/server.crt",
    verify_mode: "none"
  }
end

3. Webpacker 設定ファイル編集

dev_server の https: falsehttps: true に変更する。 

config/webpacker.yml
development:
  <<: *default

  dev_server:
    host: 0.0.0.0
    port: 8080
    https: true

4. 動作確認

https://localhost:3001/ にアクセスして HTTPS でアクセスできることを確認する。
ローカル環境でも HTTPS を利用した動作確認ができるようになりました。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away