3
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Mac のローカルで Web アプリを HTTPS で動かす

Last updated at Posted at 2021-07-30

(2024.10 追記) SAN に対応した新しい記事を書いたのでこちらを見たほうがいい
OpenSSL コマンドで自己署名 SSL/TLS サーバ証明書を作成する (SAN 対応) - Qiita

「Mac のローカルで Web アプリの開発環境を作りたいけど諸事情により HTTPS (TLS/SSL) が必須」という場合にシュッと作るためのメモ。

これを書いたときは macOS Big Sur でやった。

自己署名証明書を作成

$ openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout local.key -out local.crt -subj "/CN=*.local"

秘密鍵 local.key と自己署名証明書 local.crt が作成される。

※ Common Name (CN) は指定しなくてもいいのかもしれない。

証明書を信頼する

作成した自己署名証明書をキーチェーンアクセスに追加して「SSL」と「X.509基本ポリシー」を「常に信頼」するように設定する。

image.png

名前解決できるようにする

今回は開発環境を作りたいだけなので hosts ファイルをいじる。

/etc/hosts
127.0.0.1       example.local

Web サーバを動かす

ここは動かしたい Web サーバごとに異なるが、今回は試しに Node.js 製の http-server で静的なサイトを動かしてみる。

$ brew install http-server
$ http-server -p 443 -S -C <証明書ファイル> -K <秘密鍵ファイル>

Web ブラウザから https://example.local/ にアクセスすれば見れるはず。

3
9
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
3
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?