Google Compute Engine 上的 SSL with nodejs

SSL on Google Compute Engine with nodejs

总结:

我正在尝试在 Google 的计算引擎 (GCE) 上设置一个 Node.js 服务器来使用 HTTPS,但是通过 https://....

访问时,远程服务器似乎没有响应

到目前为止我尝试了什么:

我已经从 Comodo 获得了证书,将其放在后端,将其包含在代码中,并创建了一个 HTTPS 服务器,如下所示:

var app = express();
var https = require('https');
var fs = require('fs');

var options = {
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.crt'),
};

...
        https.createServer(options,app).listen('443',function(){
                console.log('https ready')
        });

我还添加了以下防火墙规则:

gcloud compute firewall-rules create allow-https --description "https server" --allow tcp:443
--format json

当我 运行 我本地机器上的服务器并尝试使用 https://localhost:443 到 Chrome 访问它时,我得到了预期的:

This server could not prove that it is localhost; its security certificate is from www.domain_name.com. This may be caused by a misconfiguration or an attacker intercepting your connection.

表示服务器已正确配置为能够识别 https 请求,但由于证书不属于本地主机,因此会产生警告。

问题:

当我在我的 GCE 实例上 运行 相同的代码时,运行 s 在与证书关联的域名上,我没有得到服务器的响应。此外,根据 tcpdump 传入 https 正确端口上的流量:

I 运行 netstat -ltnp 结果如下:

我的问题是:如何让我的 GCE 实例响应 https 请求?我还应该做什么或测试什么?

我发现了几个关于这个主题的问题 ( ,, q3, q4),似乎我做了那里推荐的所有事情,但我的问题仍然存在。

可能您 运行 服务器是非 root 用户,它无法绑定到端口 443(这是一个特权端口)。