實現port80可以容納多個服務,可跨Apache與NodeJS使用
var http = require('http'), httpProxy = require('http-proxy'), proxy = httpProxy.createProxyServer({}), url = require('url'); http.createServer(function(req, res) { var hostname = req.headers.host.split(":")[0]; var pathname = url.parse(req.url).pathname; var clear_path = pathname.replace('\/', ''); switch(hostname) { case 'aaa.cumi.co': proxy.web(req, res, { target: 'http://127.0.0.1:7005' }); //Apache break; case 'bbb.cumi.co': proxy.web(req, res, { target: 'http://127.0.0.1:7004' }); //Nginx break; case 'ccc.cumi.co': proxy.web(req, res, { target: 'http://127.0.0.1:7003' }); //NodeJs break; case 'ddd.cumi.co': proxy.web(req, res, { target: 'http://127.0.0.1:7002' }); //IIS or ... break; case 'eee.cumi.co': if(clear_path.match(/^phpMyAdmin/)){ proxy.web(req, res, { target: 'http://127.0.0.1:5000' }); //apache-default } else { proxy.web(req, res, { target: 'http://127.0.0.1:7001' }); //NodeJs } break; default: proxy.web(req, res, { target: 'http://127.0.0.1:5000' }); } }).listen(80, function() { console.log('proxy listening on port 80'); });
酷米 © All Rights Reserved.