Node.js HTTPS服务器ERR_EMPTY_RESPONSE [英] Node.js HTTPS server ERR_EMPTY_RESPONSE

查看:590
本文介绍了Node.js HTTPS服务器ERR_EMPTY_RESPONSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr 创建了server.key和server.csr文件。我用startssl.com创建了一个SSL证书,它给了我一个证书文件。然后在我的node.js应用程序中,我读取密钥和证书文件:

I created the server.key and server.csr files using openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr. I created a SSL certificate with startssl.com which gave me a certificate file. Then in my node.js application I read the key and certificate files:

var app = module.exports = express.createServer({
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.cert')
});

但是,现在我从我的应用程序得到一个空的响应,没有收到数据消息。可能是什么导致了这个?我对SSL非常新,以及它是如何工作的,所以非常感谢任何帮助。

But, now I get an empty response from my application, a "No data received" message. What could be causing this? I'm very new to SSL and how it all works, so any help with this is very much appreciated.

更多信息:我生成了两个文件,密钥和csr文件,在我的VPS服务器(生产服务器)上,现在我正在尝试让它们在我的localhost上工作(首先,在我将代码提交到生产之前;我必须在进行git提交之前测试它是否有效)。因此,可能是因为我的localhost(开发环境)与我的VPS服务器(生产环境)位于不同的域。可能是这种情况吗?如果是这样,我如何才能将其发送到localhost和生产环境使用相同证书的位置?

More info: I generated the two files, key and csr files, on my VPS server (production server), and now I'm trying to get them to work on my localhost (firstly, before I commit my code to production; I have to test that it works before making a git commit). So, it could be due to the fact that my localhost (development environment) is on a different domain from my VPS server (production environment). Could this be the case? If so, how can I make it to where the localhost and production environment use the same certificate?

或者,您是否建议我为我的开发环境创建另一个证书?我看到的唯一问题是,我的开发环境没有域名,因为它是在本地完成的。为了简单起见,我宁愿使用相同的证书(即使这意味着一个破坏的锁图标或localhost上的东西)。

Or, would you suggest I create another certificate for my development environment? The only problem I see with that, is that I wouldn't have a domain for my dev environment because it's done locally. I'd rather much use the same certificate (even if that means a broken lock icon or something on localhost) for the sake of simplicity.

推荐答案

您可以使用 curl --insecure --verbose 连接到您的应用程序来解决错误。通常,您不应在多个主机上使用SSL证书。您可以在本地进行自签名测试,并在生产中使用startssl。但无论如何,证书中的CN需要匹配用于连接到站点的主机名,以避免恼人的浏览器警告。您可以随时为您的计算机组建域名,例如 sam.local ,并将其放在/ etc / hosts文件中,并将其用于您的自签名证书以及您的浏览器地址栏。

You can troubleshoot errors by connecting to your application with curl --insecure --verbose. Generally you shouldn't use an SSL certificate on more than one host. You can make a self-signed one to test locally and use the startssl one in production. But in any case, the CN in the cert needs to match the hostname used to connect to the site to avoid annoying browser warnings. You can always make up a domain name for your machine like sam.local and put that in your /etc/hosts file and use that in your self-signed certificate as well as your browser address bar.

这篇关于Node.js HTTPS服务器ERR_EMPTY_RESPONSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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