我的服务器中有两个Node.js应用程序。他们正在向港口上市55555
。这是目录结构。
/home/myuser
/.htaccess
/package.json
/server.js
/foo.com
/node_modules
/public
/index.html
/package.json
/server.js
/bar.com
/node_modules
/public
/index.html
/package.json
/server.js
/home/myuser/server.js 内容
'use strict';
// Module dependencies.
var express = require('express');
var vhost = require('vhost');
var port = process.env.PORT || 55555;
function createVirtualHost(domainName, nodeApp) {
return vhost(domainName, nodeApp);
}
//Create server
var app = express();
var fooApp = require('./foo.com/server.js').app;
var barApp = require('./bar.com/server.js').app;
//Create the virtual hosts
var fooHost = createVirtualHost("www.foo.com", fooApp);
var barHost = createVirtualHost("www.bar.com", barApp);
//Use the virtual hosts
app.use(fooHost);
app.use(barHost);
//Start server
app.listen( port, function() {
console.log( 'Express server listening on port %d in %s mode', port, app.settings.env );
});
/home/myuser/.htaccess 内容
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:55555/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:55555/$1 [P,L]
当我尝试访问www.foo.com
时,出现以下错误:
无法获取 /foo.com/index.html.var
当我尝试访问www.bar.com
时,出现以下错误:
无法获取 /bar.com/index.html.var
www.foo.com:55555
但我可以使用端口访问这两个站点www.bar.com:55555
不使用端口如何访问网站?