1

要件があります。expressjsを使用するwww.myhost.comや、基本的なnodejs https.createServer()を使用する* .h.myhost.comのように、異なるモジュールを使用してHOSTヘッダーに依存します。そして、それらは同じポートで動作します。

https.createServer(options,function(req, res){
   if(req.host === "www.myhost.com"){
       express.handle(req,res) //what I hope
       return 
   }
   //handle by normal way
})

これを行う方法?

4

1 に答える 1

5

nodejitsuによるnode-http-proxyを使用できます。これを使用して、異なるサブドメインで実行されている複数のアプリケーションをデプロイおよび構成します。

例:

var express = require('express'),
  https = require('https'),
  proxy = require('http-proxy');

// define proxy routes
var options = {
  router: {
    'www.myhost.com': '127.0.0.1:8001',
    '*.h.myhost.com': '127.0.0.1:8002'
  }
};

// express server for www.myhost.com
var express = express.createServer();

// register routes, configure instance here
// express.get('/', function(res, req) { });

// start express server
express.listen(8001);

// vanilla node server for *.h.myhost.com
var vanilla = https.createServer(options,function(req, res){
  // handle your *.h.myhost.com requests
}).listen(8002);

// start proxy
var proxyServer = httpProxy.createServer(options);
proxyServer.listen(80);

http-proxyルーティングテーブル(* .h.myhost.com)でワイルドカードを使用するかどうかはわかりませんが、これらの値はnode-http-proxyで正規表現に変換されるため、機能すると思います。

于 2011-03-07T09:40:07.243 に答える