AdguardTeam / AdGuardHome

Network-wide ads & trackers blocking DNS server
https://adguard.com/adguard-home.html
GNU General Public License v3.0
23.56k stars 1.73k forks source link

Use Traefik with subpath redirection. #5478

Open k-matvey opened 1 year ago

k-matvey commented 1 year ago

Prerequisites

Description

What problem are you trying to solve?

I have a problem using AGH behind Traefik with subpath, because AGH on login always return HTTP 302 code with location = /login.html. For use AGH with subpath we must rewrite http response header location to /adghome/login.html.

Proposed solution

To do this we can use Rewrite Headers plugin for Traefik. First of all we must enable plugin in traefik.yml config:

...
experimental:
  plugins:
    rewriteHeaders:
      modulename: "github.com/bitrvmpd/traefik-plugin-rewrite-headers"
      version: "v0.0.1"

After that we can enable middleware for adguardhome container with labels:

...
  'traefik.http.routers.adghome.middlewares=adghome,adglocation'
  'traefik.http.middlewares.adghome.stripprefix.prefixes=/adghome'
  'traefik.http.middlewares.adglocation.plugin.rewriteHeaders.rewrites.response[0].header=Location'
  'traefik.http.middlewares.adglocation.plugin.rewriteHeaders.rewrites.response[0].regex=^/(.+)$'
  'traefik.http.middlewares.adglocation.plugin.rewriteHeaders.rewrites.response[0].replacement=/adghome/$1'
...

Now dashboard working fine.

May be this solution can be added for AGH documentation ?

spantaleev commented 1 year ago

It's not just the homepage that redirects to /login.html without caring about the base path.

When running AdGuard Home the first time around, the homepage would also redirect to /install.html the same way. This is a one-time annoyance, so it's not as bad as the login thing, but nevertheless a problem.

It'd be nice if one could configure a "public base URL" somehow.

thevoltagesource commented 3 months ago

+1 for this fix. Being able to configure a base path would remove a lot of reverse proxy workarounds.

overwatch3560 commented 3 months ago

@ainar-g