LoginSignup
25
21

More than 1 year has passed since last update.

http-serverによるローカル HTTPS server 構築 (5分でできる)

Last updated at Posted at 2020-04-13

はじめに

https環境でないと動かないJavascript APIなどを試験するのにローカルになんちゃってhttpsサーバが欲しくなった。以下の手順が最も簡単で速い方法だと思ったのでここに記す。

mkcertのインストール

Macの場合

% brew install mkcert

他の環境でも適宜インストールしてください。

CAのインストール(初回のみ)

% mkcert -install

サーバ証明書、秘密鍵生成

下記コマンドで適当なフォルダに証明書、秘密鍵を生成。mkcertコマンドには証明したいアドレス, ホスト名を全て指定。 ローカルネットワークの他PCからもアクセスしたいので、自PCのPrivate Address (e.g. 192.168.11.2)も追加(各自適当に)。

% mkdir ~/cert
% cd cert
% mkcert localhost 127.0.0.1 192.168.11.2
% ls
localhost+2-key.pem localhost+2.pem

http-serverインストール

% npm install -g http-server

サーバ起動

サーバ証明書、秘密鍵を指定してhttp-serverを起動する.

% http-server -c-1 . --ssl --key ~/cert/localhost+2-key.pem --cert ~/cert/localhost+2.pem

ブラウザから https://localhost/, https://192.168.11.2/ などにアクセス.

25
21
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
25
21