本地站点创建SSL证书,并且信任

引言

我们通常建站测试的时候,都是直接127.0.0.1这样访问的,也就是使用的http协议,那么如果需要HTTPS协议访问本地站点呢?

准备工作

  1. mkcert
  2. Web浏览器一个(Chrome)
  3. Windows系统

命令介绍

$ mkcert -install
    Install the local CA in the system trust store.

    $ mkcert example.org
    Generate "example.org.pem" and "example.org-key.pem".

    $ mkcert example.com myapp.dev localhost 127.0.0.1 ::1
    Generate "example.com+4.pem" and "example.com+4-key.pem".

    $ mkcert "*.example.it"
    Generate "_wildcard.example.it.pem" and "_wildcard.example.it-key.pem".

    $ mkcert -uninstall
    Uninstall the local CA (but do not delete it).

步骤

执行 mkcert -install 安装证书
执行 mkcert localhost 127.0.0.1 ::1 生成证书文件

会生成两个文件localhost.pem localhost-key.pem
我这儿重命名了一下,改成了localhost.crt 和 localhost.key

配置WEB服务器应用,如nginx
image.png

打开certmgr.msc导入刚刚生成的证书
image.png
image.png

重启一下浏览器,就可以看到效果了。

image.png
image.png

实测:chrome edge可以,但是firefox仍然存在告警(但是可以例外)

评论 0

还没有评论,来说点什么吧。

提交后需要审核才会公开。