在开发过程中会遇到需要在本地部署https的情况,通常的做法是使用自签名的根证书,并信任该证书。但是操作过程繁琐,容易出错。

今天我们介绍另一个比较方便快捷的方式:mkcert

1
mkcert is a simple tool for making locally-trusted development certificates. It requires no configuration.

mkcert是用于创建本地可信任开发证书的简易工具,无需额外配置。

这是官方对该工具的说明。

安装

Mac 下通过brew安装

1
brew install mkcert

创建证书

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
$ mkcert -install
Created a new local CA 💥
The local CA is now installed in the system trust store! ⚡️
The local CA is now installed in the Firefox trust store (requires browser restart)! 🦊

$ mkcert example.com "*.example.com" example.test localhost 127.0.0.1 ::1

Created a new certificate valid for the following names 📜
 - "example.com"
 - "*.example.com"
 - "example.test"
 - "localhost"
 - "127.0.0.1"
 - "::1"

The certificate is at "./example.com+5.pem" and the key at "./example.com+5-key.pem"

具体使用参数参考官方文档说明。

mkcert