0

I'm trying to make a reverse proxy to my router's web interface with apache in the subdirectory /lan/

My router's IP address is 172.16.0.1 and can be accessed through http://172.16.0.1/

I'm using the following directives to try to accomplish this:

    <Location /lan>
            ProxyPass http://172.16.0.1
            ProxyPassReverse http://172.16.0.1
    </Location>

The problem is that is rewrites http://172.16.0.1/.js or http://172.16.0.1/.css to https://my.domain/.js or https://my.dmain/.css instead of https://my.domain/lan/.js and https://my.domain/lan/.css

I was able to get this exact setup to work with pihole with these directives:

    <Location /pi-hole>
            ProxyPass http://172.16.81.53/admin/
            ProxyPassReverse http://172.16.81.53/admin/
    </Location>

and it properly rewrites everything under /admin/ instead of the root

I have tried several things but nothing has worked I'd really appreciate any help

2

The URLs for the .css and .js files are generated by the router itself, and they are located inside the HTML code your router sends to your client.

Apache does not modify HTML response bodies with ProxyPassReverse, it only modifies response headers.

You need to use Apache's mod_substitute for replacing the response body. You can find more information on it at https://httpd.apache.org/docs/current/mod/mod_substitute.html.

You need to be careful when specifying the rules for mod_substitute, since changing the HTML body in incorrect ways can make the whole admin interface to work incorrectly.

A better way would be to use a subdomain for the reverse proxy.

  • I cant check if this resolves the issue right now but if i does I'll be sure to give you the correct answer. I want to avoid using a subdomain because then people can easily connect by doing a dns lookup on my domain, and I use cloudflare so I won't be able to enforce a maximum number of attempts or else that will kill ALL traffic from cloudflare, not just the attacker. – Desultory Aug 8 '17 at 15:44
  • I am not sure if I understood your text correctly, but there can be subdomains also in Cloudflare, and those are protected in the same way as the main domain. – Tero Kilkanen Aug 8 '17 at 15:59
  • yes and no, I use fail2ban with the apache_auth mod enabled, if someone accessing a site through a cloudflared IP triggers that jail then the cloudflare IP they went through is banned and that makes it so that most, if not all cloudflare users accessing my site will be told the site is offline, unless there is some way to get fail2ban to ban the origin ip, running sites with authentication over coudflared ips causes bad problems – Desultory Aug 8 '17 at 20:41
  • I am sure there is a way for Apache to use Cloudflare's header for the client IP instead of Cloudflare IP address for its operation. In nginx, one can use set_real_ip directive for this. – Tero Kilkanen Aug 9 '17 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.