簡體   English   中英

使用node-http-proxy,通過proxyRequest更改URL

[英]Using node-http-proxy, changing url with proxyRequest

修改node-http-proxy示例時 ...

問題:當手動將req.headers.host更改為遠程主機('example.com')時,瀏覽器中的URL並未更改。

注意:我以為這可行,但是當以google.com為例時,事實證明google正在檢測代理並更改主機。

問題:有沒有辦法每次都將瀏覽器中的URL更改為遠程主機(例如example.com)? 謝謝!

var util = require('util'),
    colors = require('colors'),
    http = require('http'),
    httpProxy = require('../../lib/node-http-proxy');

//
// Http Server with proxyRequest Handler and Latency
//
var proxy = new httpProxy.RoutingProxy();
http.createServer(function (req, res) {
  req.headers.host = 'example.com'; // manually setting example.com
  var buffer = httpProxy.buffer(req);
  setTimeout(function () {
    proxy.proxyRequest(req, res, {
      port: 80,
      host: 'example.com',
      buffer: buffer
    });
  }, 200);
}).listen(8004);



util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8004 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);

可以做到這一點的一些解決方案是:

  • 發出301重定向。
  • 使用IPTables進行DNAT並更改目標地址。
  • 使用TPROXY透明地代理請求,而無需修改數據包。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM