Reverse Proxy

#1

Hi
I would like to reverse proxy a few sites for geo location reasons (I don’t own the final domain). I thought it would be as easy as setting up proxy pass on a domain I own with the location pointing to the target domain and while this works for the homepage, as soon as I click a link it starts being served from the target domain.

I’m sure I’m doing something obviously wrong!

I was going to setup a VPN and route traffic depending on rules but my unifi usg doesn’t seem to support “URL” based routing. I could setup *sense and remove my usg, but that would make me a little bit sad.

Thoughts please

0 Likes

#2

single core

multi core

ideal

0 Likes

#3

You need to replace all links on the page and catch redirects.
Nginx can do it either via sub_filter or with Lua (if it’s compiled with it). I use something similar to this:

        location / {
                set $site "old.reddit.com";

                resolver 109.248.43.1 valid=3600s;
                resolver_timeout 15s;

                proxy_set_header Accept-Encoding "";
                proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                proxy_ssl_session_reuse on;

                proxy_set_header Connection "Keep-Alive";
                proxy_set_header Proxy-Connection "Keep-Alive";
                proxy_set_header Host $site;
                proxy_redirect https://$site/ https://$host/;

                body_filter_by_lua '
                        ngx.arg[1] = ngx.re.gsub(ngx.arg[1], "//www.reddit.com", "//reddit.mysite.com")
                        ngx.arg[1] = ngx.re.gsub(ngx.arg[1], "//reddit.com", "//reddit.mysite.com")
                        ngx.arg[1] = ngx.re.gsub(ngx.arg[1], "//old.reddit.com", "//reddit.mysite.com")
                ';

                proxy_pass https://$site;
        }

If you don’t have Lua, just do something like sub_filter '//old.reddit.com' '//reddit.mysite.com';

3 Likes

#4

That’s interesting

0 Likes

#5

Try this : MITM Proxy

0 Likes