为localhost创建受信任的自签名SSL证书(用于Express / Node)

编程入门 行业动态 更新时间:2024-10-10 17:32:11
本文介绍了为localhost创建受信任的自签名SSL证书(用于Express / Node)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尝试遵循有关创建自签名证书以使用本地主机的各种说明,大多数说明似乎适用于IIS,但我正在尝试使用Nodejs / Express。没有一个工作正常,因为在安装证书时,它不被信任。以下是我尝试过的失败:

Trying to follow various instructions on creating a self-signed cert for use with localhost, Most of the instructions seem to be for IIS, but I'm trying to use Nodejs/Express. None of them work properly because while the cert gets installed, it is not trusted. here's what I've tried that fails:

  • 如何为本地主机创建自签名证书
  • https:// www.digitalocean/community/articles/how-to-create-a-ssl-certificate-on-nginx-for-ubuntu-12-04/
  • blogs.developerforce/开发者关系/ 2011/05 / generate-valid-self-signed-certificates.html
  • www.robbagby/iis/self-已登录证书上-IIS-7最容易的方式和 - 的最有效的单向/
  • How can I create a self-signed cert for localhost?
  • www.digitalocean/community/articles/how-to-create-a-ssl-certificate-on-nginx-for-ubuntu-12-04/
  • blogs.developerforce/developer-relations/2011/05/generating-valid-self-signed-certificates.html
  • www.robbagby/iis/self-signed-certificates-on-iis-7-the-easy-way-and-the-most-effective-way/

有人可以提供可以做到这一点的工作流吗? 我可以安装证书,但我无法使用chrome(v32)或IE(v10)信任证书。

Can someone offer a workflow that can do this? I can get a cert installed, but I can't get the cert to be trusted in either chrome (v32) or IE (v10).

编辑:在评论中建议问题是不信任的证书根。我通过IE安装了证书,但它仍然不被信任。

it was suggested in comments that the problem is no trusted cert-root. I installed the cert via IE but it's still not being trusted.

推荐答案

您可以尝试使用openSSL生成证书。 看看这个。

You can try openSSL to generate certificates. Take a look at this.

您将需要一个.key和.crt文件将HTTPS添加到节点JS express服务器。一旦你生成这个,使用这个代码来添加HTTPS到服务器。

You are going to need a .key and .crt file to add HTTPS to node JS express server. Once you generate this, use this code to add HTTPS to server.

var https = require('https'); var fs = require('fs'); var express = require('express'); var options = { key: fs.readFileSync('/etc/apache2/ssl/server.key'), cert: fs.readFileSync('/etc/apache2/ssl/server.crt'), requestCert: false, rejectUnauthorized: false }; var app = express(); var server = https.createServer(options, app).listen(3000, function(){ console.log("server started at port 3000"); });

这在我的本地机器以及我部署过的服务器中正常工作。我在服务器中的一个是从goDaddy购买的,但是localhost有一个自签名证书。

This is working fine in my local machine as well as the server where I have deployed this. The one I have in server was bought from goDaddy but localhost had a self signed certificate.

然而,每个浏览器都会出现一个错误,表示连接不受信任,你想要继续。点击继续后,它工作正常。

However, every browser threw an error saying connection is not trusted, do you want to continue. After I click continue, it worked fine.

如果有人绕过了带有自签名证书的错误,请启示。

If anyone has ever bypassed this error with self signed certificate, please enlighten.

更多推荐

为localhost创建受信任的自签名SSL证书(用于Express / Node)

本文发布于:2023-11-24 17:01:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626079.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:证书   SSL   localhost   Express   Node

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!