如何简单的配置本地HTTPS开发环境?


本地开发环境HTTPS部署

自从有了Let's Encrypt ,使用https的成本越来越低,更多的网站开始使用https,本地开发环境调试https成为一种常态。配置自签名证书的步骤还是有些繁琐。发现一个新的工具mkcert。mkcert可以自动在本地安装CA证书,兼容各种浏览器,可以为本地开发使用的域名生成证书,甚至localhost和127.0.0.1都可以。https://github.com/FiloSottile/mkcert/releases

按照官方文档安装好程序,windows可以在releases页面下载到本地,将可执行程序放在一个%PATH%目录中即可。

下面时官方的操作

$ 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"

mkcert -install的时候火狐可能有配置失败的情况,每个人的系统不同。

nginx配置参考

 server {
    listen       443 ssl;
    server_name test.lnmp;
    root    "/mnt/hgfs/htdocs/wj/test";
    location / {
        index  index.html index.htm index.php l.php;
        try_files $uri $uri/ /index.php?$args;
        autoindex  off;
    }
    include enable-php.conf;
    ssl_certificate /mnt/hgfs/htdocs/lnmp/cert/test.lnmp.pem;
    ssl_certificate_key /mnt/hgfs/htdocs/lnmp/cert/test.lnmp-key.pem;
}

用上这个工具可以方便的在本地搭建https的开发环境了。

Archives