localhost自签名SSL证书

运行命令
在本地的开发环境中需要使用证书,先生成自签名证书,再信任。

openssl req -x509 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=localhost' -extensions EXT -config <( \
   printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

文档教程:https://letsencrypt.org/docs/certificates-for-localhost/

注意
自签名证书默认有效期是30天,可以用参数-days 来指定有效期。
当然,自己用的可以直接使用 -days 3650 来指定十年有效,够用。
localhost自签名SSL证书_第1张图片

信任方法
Safari中访问这个网站,然后单击警告框末尾的「访问网站」
localhost自签名SSL证书_第2张图片

你可能感兴趣的:(localhost自签名SSL证书)