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

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

启用了proxy和proxy_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');
});

10-04 22:09
查看更多