【问题标题】:Using node-http-proxy, changing url with proxyRequest使用 node-http-proxy,用 proxyRequest 改变 url
【发布时间】:2013-06-21 03:58:58
【问题描述】:

修改node-http-proxy example时...

问题:当手动将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);

【问题讨论】:

    标签: node.js node-http-proxy


    【解决方案1】:

    可以做到这一点的一些解决方案是:

    • 发出 301 重定向。
    • 使用 IPTables 进行 DNAT 并更改目标地址。
    • 使用 TPROXY 透明地代理请求而不修改 数据包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-14
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 1970-01-01
      • 2012-09-27
      相关资源
      最近更新 更多