gpt4 book ai didi

javascript - 浏览 Node.js 服务器时出现 502(代理错误)

转载 作者:太空宇宙 更新时间:2023-11-03 22:37:35 25 4
gpt4 key购买 nike

我已经通过代理、proxy_http 模式使用 Apache 服务器配置了 Node.js 服务器,并且工作正常。但是现在,当我启动 Node.js 服务器时,我在 ssh 控制台上收到正在运行的通知消息:“好的,服务器正在运行”,但是当我通过浏览器访问 Node.js 服务器时 http://example.com/node/,我收到 502 错误(代理错误) - 在我获得 200 状态之前!

我不知道为什么现在我无法获得 200 状态!我没有对 Node.js 服务器文件进行任何更改。所有者是 root:root。我重新启动了 Ubuntu 12.04 服务器,重新启动后它就可以工作了。

模块 proxyproxy_http 已启用。

我从 Apache 日志中收到以下错误:

(20014)Internal error: proxy: error reading status line from remote server localhost:9000

proxy: Error reading from remote server returned by /node


下面是启用代理的站点可用 /etc/apache2/sites-available/example.com 配置

<VirtualHost *:80>

.
.
ProxyPass /n http://localhost:9000/
ProxyPassReverse /n http://localhost:9000/
.
.
</VirtualHost>

Node.js 服务器代码:

var http=require('http');
var mysql = require('mysql');
var util = require('util');
var url = require('url');

var server=http.createServer(function(req,res){
//res.end('Connected');
});


server.on('listening',function(){
console.log('ok, server is running');
});

server.listen(9000);

我非常感谢您的意见,因为我已经尝试了很多但没有运气:(

谢谢。

最佳答案

如果我在服务器上评论响应,那么它将不起作用并会收到错误 502。应该是:

var server=http.createServer(function(req,res){
res.end('Connected');
});

关于javascript - 浏览 Node.js 服务器时出现 502(代理错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23598948/

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