我正尝试在Apache服务器上运行一个Node.js应用程序,监听端口80,下面是我的虚拟主机文件:
<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');当我尝试在'localhost/node‘或ip_adress/node上运行应用程序时,我遇到了502代理错误:代理服务器从上游服务器接收到无效响应。代理服务器无法处理GET /node请求。
原因:的DNS查找失败: localhost
Apache/2.4.7 (Ubuntu)服务器,127.0.0.1端口80。
谢谢。
发布于 2016-09-16 00:41:52
在app.js中启用代理
app.enable('trust proxy');并在node.js中修复有效路由的uri:
ProxyPass /node http://localhost:8000/node
ProxyPassReverse /node http://localhost:8000/node发布于 2016-09-16 01:16:29
本地主机可能是ipv6地址,请尝试使用127.0.0.1代替
https://stackoverflow.com/questions/39516224
复制相似问题