【问题标题】:Node.js consistently giving 503 errorNode.js 始终给出 503 错误
【发布时间】:2016-10-16 09:58:32
【问题描述】:

我刚刚安装了 Node.js,让它运行了一段时间,然后尝试运行一个标准的 Hello World 程序。

var http = require("http");

http.createServer(function (request, response) {

   // Send the HTTP header
   // HTTP Status: 200 : OK
   // Content Type: text/plain
   response.writeHead(200, {'Content-Type': 'text/plain'});

   // Send the response body as "Hello World"
   response.end('Hello World\n');
}).listen(8081);

// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');

然后我启动了我为节点设置的域http://node.foobar.com - 当我上周在我的域上做了同样的事情时,我成功地让它打印了Hello World。但是现在,我不断收到503 Service Temporarily Unavailable error.

上周也发生了这种情况,在我关闭服务器,编辑代码,然后重新运行服务器后,它会 503,除非我等待几分钟再运行。然而,这一次等待没有任何区别。

域的 Apache 配置:

<VirtualHost *:80>
ServerAdmin zadmin@localhost
DocumentRoot "/var/zpanel/hostdata/zadmin/public_html/node"
ServerName node.foobar.com

ProxyRequests on
ProxyPass / http://localhost:3102/

# Custom settings are loaded below this line (if any exist)
</VirtualHost>

【问题讨论】:

  • 我知道这个问题之前已经解决了,不管是谁导致 503 的根本原因也是 NodeJS 代码本身。如果 Node.JS 代码中有错误,您的网页会很高兴地抛出 503 错误。 **这仅适用于使用相同代码遇到此问题但遇到不同问题的任何路人。

标签: javascript node.js http-status-code-503


【解决方案1】:

如何设置域?

您是否使用其他 HTTP 服务器作为代理?

请检查节点是否正在运行,如果是,请检查您的 HTTP 服务器是否也在运行。

也许你的节点已经崩溃或者只是没有运行。

另一个测试是直接连接你的节点:

http://127.0.0.1:8081/

【讨论】:

  • 我在 VPS Unix 服务器上运行它,无法直接访问 127.0.0.1:8081。域是使用 Apache VirtualHost 设置的,如编辑中所示。我做了ps aux | grep node 并看到节点正在运行。
  • 其实你给我指出了正确的方向,谢谢!我的 VHost 设置使用端口 3102
  • 所以问题是 Apache HTTP 服务器试图通过错误的端口访问节点并导致 503 错误。对吗?
猜你喜欢
  • 2011-06-18
  • 1970-01-01
  • 2017-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-13
  • 2020-06-03
  • 2020-07-01
相关资源
最近更新 更多