LetsEncrypted Node.js HTTPS Express无法从浏览器访问

问题描述 投票:0回答:2

我按照本教程使用SSL保护NGINX:https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

我明确选择将所有请求重定向到HTTPS

现在,当访问我的网页www.example.com时,它正确地将我重定向到https://www.example.com并显示默认的NGINX文本。

我希望Express能够在那里运行,所以我制作了这个小小的脚本来测试一下:

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

var options = {
  key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
  cert: fs.readFileSync('/etc/letsencrypt/live/example.com/cert.pem'),
  ca: fs.readFileSync('/etc/letsencrypt/live/example.com/chain.pem')
};

https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8000);

该页面根本不会加载。我究竟做错了什么?

node.js nginx https lets-encrypt
2个回答
0
投票

请确认您的监听端口。 Nginx的默认端口是8080,根据你的代码,它会尝试收听8000。


0
投票

这是一个防火墙问题。

我忘了允许上述TCP端口。

© www.soinside.com 2019 - 2024. All rights reserved.