【发布时间】:2015-11-12 06:08:46
【问题描述】:
我的 Apache 配置:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName mydomain.com
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
我的 NodeJS:
var app = require('express')();
var http = require('http').Server(app);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
http.listen(3000, function(){
console.log('Listening on *:3000');
});
这目前在连接到mydomain.com 时有效:它将成功返回index.html。当我尝试连接到mydomain.com/foo 时出现问题。理想情况下,这只会转到http://localhost:3000/foo,但它会显示"Cannot GET /foo"。
我如何将mydomain.com/* 重定向到我的 NodeJS 项目目录中的相应路径,而不需要大量:
app.get('/foo', function(req, res){
res.sendFile(__dirname + '/foo');
});
app.get('/bar', function(req, res){
res.sendFile(__dirname + '/bar');
});
app.get('/foo/bar', function(req, res){
res.sendFile(__dirname + '/foo/bar');
});
?
【问题讨论】: