【问题标题】:LetsEncrypted Node.js HTTPS Express inaccessible from browserLetsEncrypted Node.js HTTPS Express 无法从浏览器访问
【发布时间】:2018-05-09 10:07:48
【问题描述】:

我按照本教程使用 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


    【解决方案1】:

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

    【讨论】:

    • 我确认。没有错误,除了当我尝试允许用户使用以下命令使用默认端口 (80) 时: sudo apt-get install libcap2-bin sudo setcap cap_net_bind_service=+ep /usr/local/bin/node
    【解决方案2】:

    这是防火墙问题。

    我忘记允许上面提到的 TCP 端口了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-04
      • 2019-01-19
      • 2014-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      相关资源
      最近更新 更多