2016-03-24 7 views
1

逆方向ではなくネットワークBに接続できるネットワークAがあるとします。 AからBへの接続を確立して、Bで動作しているプロキシがBの内部の接続をリッスンしてAに戻るようにすることは可能ですか?nodeJSを使った穴あけ?

例:ネットワークAのポート8080上のHTTPサーバA1はネットワークBのクライアントには見えませんが、ネットワークAの特別なクライアントPAはネットワークBのプロキシPBに接続し、 PBはポート8080でリッスンし、元のHTTP Server A1に要求を転送できるようになりました。

理想的には2つのnodeJSスクリプトがPAとPBの機能性を実現できました。

答えて

0

それは(私はまさにそれを追跡苦労のビットを持っていた)ご希望の結果を得るために、「プロキシ創業」の問題だ。そこから

var http = require('http'), 
    httpProxy = require('http-proxy'); 
// 
// Create your proxy server and set the target in the options. 
// 
httpProxy.createProxyServer({target:'http://PB:8080'}).listen(8080); // See (†) 

// 
// Create your target server 
// 
http.createServer(function (req, res) { 
    res.writeHead(200, { 'Content-Type': 'text/plain' }); 
    res.write('why hello there PA' + '\n' + JSON.stringify(req.headers, true, 2)); 
    res.end(); 
}).listen(8080); 

https://github.com/nodejitsu/node-http-proxy#setup-a-basic-stand-alone-proxy-server

http-proxyモジュールを使用してください。

関連する問題