修改 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);
最佳答案
可以实现此目的的一些解决方案是:
- 发出 301 重定向。
- 使用 IPTables 进行 DNAT 并更改目标地址。
- 使用 TPROXY 透明地代理请求,而无需修改 数据包。
关于node.js - 使用node-http-proxy,通过proxyRequest更改url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17227475/