代理错误502,在apache2服务器上运行节点js app

时间:2016-09-15 16:38:27

标签: javascript node.js apache proxy ubuntu-14.04

我试图在Apache服务器侦听端口80上运行Node.js应用程序 这是我的Virtualhost文件:

    <VirtualHost *:80>

ServerName mikus

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

ProxyPreserveHost On

ProxyPass /node http://localhost:8000/
ProxyPassReverse /node  http://localhost:8000/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>

这是我的app.js文件:

var express = require('express');
var app = express();


app.get('/node', function(req, res) {
  res.setHeader('Content-Type', 'text/plain');
  res.end('Welcome apache');
});

app.listen(8000, 'localhost');

当我试图在&#39; localhost / node&#39;或ip_adress / node,我有502代理错误:代理服务器从上游服务器收到无效响应。 代理服务器无法处理请求GET /节点。

原因:DNS查找失败:localhost

Apache / 2.4.7(Ubuntu)服务器,位于127.0.0.1端口80。

感谢。

2 个答案:

答案 0 :(得分:0)

app.enable('trust proxy'); 中启用代理:

ProxyPass /node http://localhost:8000/node
ProxyPassReverse /node  http://localhost:8000/node

并修复node.js中有效路由的uri:

gets

答案 1 :(得分:0)

localhost可能是ipv6地址,请尝试127.0.0.1 insteed

相关问题