503将node.js部署从server.js切换到index.js(初学者)时出错

时间:2014-06-01 02:31:54

标签: javascript node.js

作为参考,我正在使用 Node Beginner Book 的教程,这是代码的来源。

编辑:基于一个建议,我通过ssh进入并手动启动我的index.js,服务器正在运行('Hello World'而不是503)!然而,一旦我退出shell,服务器再次关闭,我得到503s。

/编辑

我可以通过修改server.js文件来运行简单的服务器。我使用以下示例代码:

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();
}).listen(8080);

但是,当我转到下一课时,除了server.js文件之外还引入了'index.js'文件,我在我的网站上得到503

以下是更新的server.js:

var http = require("http");

function start() {
  function onRequest(request, response) {
    console.log("Request received.");
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
  }

  http.createServer(onRequest).listen(8080);
  console.log("Server has started.");
}

exports.start = start;

还有index.js:

var server = require("./server");

server.start();

我从服务器的错误日志中得到的错误是:

[Sun Jun 01 02:26:16.925881 2014] [proxy:error] [pid 32501:tid 3071784068864] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8080 (127.0.0.1) failed
[Sun Jun 01 02:26:16.925962 2014] [proxy:error] [pid 32501:tid 3071784068864] AH00959: ap_proxy_connect_backend disabling worker for (127.0.0.1) for 60s
[Sun Jun 01 02:26:16.925977 2014] [proxy_http:error] [pid 32501:tid 3071784068864] [client 2601:9:80:13a6:2514:b96:165:4791:55892] AH01114: HTTP: failed to make connection to backend: 127.0.0.1

我不知道这意味着什么,所以任何帮助将不胜感激。我觉得唯一改变的是我要求首先调用index.js文件 - 我不知道服务器是否知道这样做,但我也不知道我知道如何检查。

编辑:根据评论将代码更改为端口3000。仍然得到似乎相同的错误:

[Sun Jun 01 03:12:14.720412 2014] [proxy:error] [pid 32716:tid 3071716927232] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8080 (127.0.0.1) failed
[Sun Jun 01 03:12:14.720475 2014] [proxy:error] [pid 32716:tid 3071716927232] AH00959: ap_proxy_connect_backend disabling worker for (127.0.0.1) for 60s
[Sun Jun 01 03:12:14.720484 2014] [proxy_http:error] [pid 32716:tid 3071716927232] [client 2601:9:80:13a6:2514:b96:165:4791:1226] AH01114: HTTP: failed to make connection to backend: 127.0.0.1
[Sun Jun 01 03:12:14.923474 2014] [proxy:error] [pid 32716:tid 3071708534528] AH00940: HTTP: disabled connection for (127.0.0.1)

1 个答案:

答案 0 :(得分:0)

您使用server.js创建了服务器,该服务器显示了" Hello World",这意味着您运行了server.js文件。 添加index.js之后,你还在执行server.js吗?我认为这不是你正在做的事情,因为很明显你现在会运行index.js而不是server.js。

因为我正在使用端口8080运行您的代码并且正在运行。