gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 00:08:13 25 4
gpt4 key购买 nike

作为引用,我使用的是 The Node Beginner Book 的教程,这是代码的来源。

编辑:根据建议,我通过 ssh 进入并手动启动了我的 index.js,服务器正常工作('Hello World' 而不是 503)!但是,我一退出 shell,服务器就再次宕机,我收到 503。

/编辑

我可以通过修改我的 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)

最佳答案

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

因为我正在使用端口 8080 运行您的代码及其工作。

关于javascript - 将 node.js 部署从 server.js 切换到 index.js 时出现 503 错误(初学者),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23976256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com