简体   繁体   English

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

[英]Getting 502 (Proxy Error) When Browsing Node.js Server

I have configured Node.js server with the Apache server via proxy, proxy_http modes and it was working fine. 我已经通过代理,proxy_http模式和Apache服务器配置了Node.js服务器,并且运行良好。 But now when I start my Node.js server, I get the running notification message on ssh console which is: "ok, server is running" , but when I access the Node.js server via browser http://example.com/node/ , I get 502 Error (Proxy Error) - Before I was getting 200 status! 但是现在当我启动Node.js服务器时,我在ssh控制台上收到正在运行的通知消息: “确定,服务器正在运行” ,但是当我通过浏览器http://example.com/node/访问Node.js服务器时http://example.com/node/ ,我得到502错误(代理错误) -在获得200状态之前!

I don't know why now I am unable to get 200 status! 我不知道为什么现在我无法获得200状态! I haven't changed anything for the Node.js server file. 我没有为Node.js服务器文件做任何更改。 The owner is root:root. 所有者为root:root。 I rebooted the Ubuntu 12.04 server and it was working after the reboot. 我重启了Ubuntu 12.04服务器,重启后它仍在工作。

The modules proxy and proxy_http are enabled. 启用了proxyproxy_http模块。

I got the below errors from Apache log: 我从Apache日志中收到以下错误:

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

proxy: Error reading from remote server returned by /node


Below is the sites-available /etc/apache2/sites-available/example.com configuration to enable proxy 以下是启用代理的站点可用的/etc/apache2/sites-available/example.com配置

<VirtualHost *:80>

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

The Node.js server code: 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);

I would greatly appreciate your inputs as I have tried a lot with no luck :( 我非常感谢您的投入,因为我尝试了很多运气:(

Thanks. 谢谢。

If I comment the response at server, then it will not work and will get Error 502 . 如果我在服务器上评论该响应,则它将无法正常工作,并会收到错误502 It should be: 它应该是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM