本地ssl证书生成_如何生成本地SSL证书

本地ssl证书生成

Note: I ran these commands on macOS. Linux should work in the same way. I don’t guarantee for Windows.

注意:我在macOS上运行了这些命令。 Linux应该以相同的方式工作。 我不保证使用Windows。

In the project root folder, run:

在项目根文件夹中,运行:

openssl req -x509 -newkey rsa:2048 -keyout keytmp.pem -out cert.pem -days 365

Now run:

现在运行:

openssl rsa -in keytmp.pem -out key.pem

You should now have the files cert.pem and key.pem in the folder.

现在,您应该在文件夹中包含文件cert.pemkey.pem

With Express/Node.js, you can load the certificate and key using this code:

使用Express / Node.js,您可以使用以下代码加载证书和密钥:

const fs = require('fs')
const https = require('https')
const app = express()

app.get('/', (req, res) => {
  res.send('Hello HTTPS!')
})

https.createServer({
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
}, app).listen(3000, () => {
  console.log('Listening...')
})

If you’re using create-react-app, change the start script in the package.json file to:

如果您使用的是create-react-app ,请将package.json文件中的start脚本更改为:

"start": "export HTTPS=true&&SSL_CRT_FILE=cert.pem&&SSL_KEY_FILE=key.pem react-scripts start",

Look at your framework/library documentation on the instructions on how to pass the certificate and key to the app.

请参阅您的框架/库文档,以获取有关如何将证书和密钥传递给应用程序的说明。

翻译自: https://flaviocopes.com/how-to-generate-local-ssl-cert/

本地ssl证书生成

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值