如何获取有效的SSL证书以进行本地开发

by Alex Nadalin

通过亚历克斯·纳达林

如何获取有效的SSL证书以进行本地开发 (How to get valid SSL certificates for local development)

A few weeks ago I bumped into mkcert, a tool written by Filippo. He is the same guy behind the popular heartbleed test tool.

几周前,我碰到了由Filippo编写的工具mkcert 。 在流行的Heartbleed测试工具背后,他是同一个人。

The tool in question answers one simple need:

有问题的工具可以满足一个简单的需求:

By creating a local root CA file that gets installed in your system, it makes all certificates issued by mkcert trusted.

通过创建在系统中安装的本地根CA文件,它将使mkcert颁发的所有证书受信任。

After downloading the latest release from GitHub, you can simply “install” it by running mkcert -install. Once that is done, you can create your first, trusted (by your own system) certificate:

从GitHub下载最新版本后,您只需运行mkcert -install即可“安装”它。 完成后,您可以创建您的第一个受信任的证书(通过您自己的系统):

$ mkcert somedomain.local

Using the local CA at "/home/alex/.local/share/mkcert" ✨

Created a new certificate valid for the following names ?
 - "somedomain.local"
 
The certificate is at "./somedomain.local.pem" and the key at "./somedomain.local-key.pem" ✅

For example, here’s how it would look like if you had to boot a Node server with SSL support:

例如,以下是您必须引导具有SSL支持的节点服务器时的样子:

const fs = require('fs')

const options = {
  key: fs.readFileSync(__dirname + '/somedomain.local-key.pem'),
  cert: fs.readFileSync(__dirname + '/somedomain.local.pem')
};

require('https').createServer(options, (req, res) => {
  res.writeHead(200)
  res.end(`Got SSL?`)
}).listen(443)

Pretty neat, eh?

很整洁吧?

What mkcert does is to simply add another CA file in your system.(I guess under /etc/ssl/certs/ca-certificates.crt, but I’m not entirely sure). Browsers consider these certificates trusted — a nice workaround to trick any HTTP client.

mkcert作用是在您的系统中简单地添加另一个CA文件。(我想在/etc/ssl/certs/ca-certificates.crt下,但是我不确定。) 浏览器认为这些证书是受信任的,这是欺骗任何HTTP客户端的不错的解决方法。

That’s it for today! Adios!

今天就这样! 阿迪奥斯!

Originally published at odino.org (1st September 2018).You can follow me on Twitter — rants are welcome! ?

最初发布于odino.org ( 2018年9月1日)。 您可以在Twitter上关注我-欢迎咆哮!

翻译自: https://www.freecodecamp.org/news/how-to-get-valid-ssl-certificates-for-local-development-ca228240fad2/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值