为localhost创建受信任的自签名SSL证书(用于Express / Node) [英] create a trusted self-signed SSL cert for localhost (for use with Express/Node)

查看:309
本文介绍了为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:

  • How can I create a self-signed cert for localhost?
  • https://www.digitalocean.com/community/articles/how-to-create-a-ssl-certificate-on-nginx-for-ubuntu-12-04/
  • http://blogs.developerforce.com/developer-relations/2011/05/generating-valid-self-signed-certificates.html
  • http://www.robbagby.com/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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆