When the target of the proxy issues a redirect (301 in this case), the proxy forwards that to the client. The client is then redirected to the actual domain and no longer using the proxy. Is there a way to prevent this redirection from affecting the client? I want the proxy to follow the redirect, but I don't want the client to leave the proxy while following this redirect.
Example case:
Assume I have a proxy running on fake-proxy.example
. When setting the target to a server ip and then setting the host to a domain on that server, the proxy tries to connect via http
. The domain is set up to redirect http
traffic to https
and issues a 301 redirect to the same domain with https
. This redirect is sent back to the client, and the client leaves fake-proxy.example
and goes to the actual domain (for the sake of this question, let's call it real-domain.example
). My configuration:
var options = {
target: {
host: '1.1.1.1'
},
headers: {
host: 'real-domain.example'
},
autoRewrite: false,
hostRewrite: false,
protocalRewrite: false
};
I appreciate the help!
It's a bit late, but a solution like the following one could help those that stumble on this post :
var http = require('http');
var url = require('url');
var request = require('request');
var host = 'http://real-domain.example';
http.createServer(onRequest).listen(3080);
function onRequest(req, res) {
var url_parts = url.parse(req.url);
request({
url: host + url_parts.pathname
}).on('error', function(e) {
res.end(e);
}).pipe(res);
}
Of course, cookies and the like won't get preserved and you will likely lose some functionality I guess, but at least, it's stable, as in you will not get redirected out of your proxy domain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With