Traefik 2 - Reverse Proxy to a Path

Hey there,

I'm trying to forward my phpMyAdmin docker container with Traefik from an internal 172.20.0.X address to a sub.domain.com/path directory. I'm using the latest version of Traefik along with the latest phpMyAdmin container.

It is my understanding that phpMyAdmin container serves the web frontend directly on port 80 at / .

I've got a basic SSL configuration of Traefik and am trying to use Docker labels to make / implement this. I've found some other tickets and Docs around explaining how to achieve this but most seem to be outdated for Traefik v1 and trying to translate this to Traefik v2 hasn't worked.

Here are my current Labels:

  • traefik.http.services.phpdb.loadbalancer.server.port 80
  • traefik.http.routers.phpdb.tls.domains[0].sans www.sub.domain.com
  • traefik.http.routers.phpdb.tls.domains[0].main sub.domain.com
  • traefik.http.routers.phpdb.tls.certresolver letsencrypt
  • traefik.http.routers.phpdb.tls true
  • traefik.http.routers.phpdb.rule (Host(sub.domain.com) && Path(/path)) || (Host(www.sub.domain.com) && Path(/path))
  • traefik.http.routers.phpdb.middlewares admin-addprefix
  • traefik.http.routers.phpdb.entrypoints https
  • traefik.http.middlewares.phpdb.headers.customrequestheaders.X-Forwarded-Proto https
  • traefik.http.middlewares.admin-addprefix.addprefix.prefix /path

When I try accessing https://sub.domain.com/path, I'm able to see the Apache2 (from the phpMyAdmin container) 4040 Not Found page but can't access the application itself. (it's not the Traefik 404 page).

If I remove all mentions of the /path from the Router or the prefix middleware, I'm able to access and use phpMyAdmin on the sub.domain.com address. However my goal is to have it only show / respond from sub.domain.com/path address.

I'm still very new so I'm sure I'm not doing something correctly somewhere and appreciate any and all help towards understanding why this isn't working.

Thank you!

  • L

To note: I've followed, tried doing this: https://docs.phpmyadmin.net/en/latest/setup.html#running-behind-haproxy-in-a-subdirectory

As well as using this to go from Traefik 1 to 2 with no results: https://doc.traefik.io/traefik/migration/v1-to-v2/#strip-and-rewrite-path-prefixes

(adding this as I couldn't include it in the previous message)

You should try PathPrefix in your rule instead of Path like :

rule: "Host(`sub.domain.co`) && PathPrefix(`/path`)"

Sorry I'm not using rule in docker like you, I'm using rule in conf file. You have to adapt to your install.

1 Like

Hey there,

Thanks for your help, I've updated my Router rule to as follows from your suggestions:

However, I'm still getting this error when I try visiting the desired URL:

image

It still seems like I'm accessing the phpMyAdmin Image apache setup but not on the right / expected path and thus, apache is returning a 404.

May i sugger you to add PMA_ABSOLUTE_URI in your docker and add the fully-qualified path as the phpMyAdmin documentation relate here ?

I've already done this, the PMA_ABSOLUTE_URI env variable doesn't modify or change the URL under which PMA is hosted on or under, it only manages the security when logging into the application to make sure you're using the right domain.

tl;dr: I've already done this, it doesn't change or do anything to Apache in the Docker container.

Here I think this is the same problem as you encountered.

It seems that traefik pass /path to the docker as the url is called and you have to rewrite it with AddPrefix:/ rule.

Hope it help.

Hey,

As explained in the above most post, I've tried passing the addprefix middleware / have been using this throughout my testing:

  • traefik.http.routers.phpdb.middlewares admin-addprefix
  • traefik.http.middlewares.admin-addprefix.addprefix.prefix /path

Along with the router rule with either:

    • traefik.http.routers.phpdb.rule = (Host(http://sub.domain.com/) && Path(/path)) || (Host(hhttp://www.sub.domain.com/) && Path(/path))

Or as you suggested earlier, the PathPrefix instead of the above mentioned Path(/path).

    • traefik.http.routers.phpdb.rule = (Host(http://sub.domain.com/) && PathPrefix(/path)) || (Host(hhttp://www.sub.domain.com/) && PathPrefix(/path))

I've also experimented with the RemovePath middleware for the /path as well without any results.

The Github ticket you linked is, at least to my understanding of Traefik relavent for Traefik v1 , not V2 as I can not find a mention or use for the PathPrefixStrip that the above Github ticket users / mentions in Traefik v2.

There is a guide on the Traefik v2 Docs that mentions how to convert from PathPrefixStrip for v2 (here: https://doc.traefik.io/traefik/migration/v1-to-v2/#strip-and-rewrite-path-prefixes) but that hasn't worked either.

I appreciate your help, I just haven't been able to assemble all these puzzle pieces into something that works yet. :frowning:

Update, I went back in and did some tweaking. Your mention of the prefix and re-reading the docs made me realize that I had to StripPrefix along with using the PathPrefix suggestion you had earlier.

After setting these rules up and restarting the Container, I'm now able to access the container interface (phpMyAdmin web interface) by browsing directly to the https://sub.domain.com/path/index.php address.

However, going to the https://sub.domain.com/path address on its own just loads up a blank page with the right Page Title. I'm assuming I'm now missing something that tells Traefik to forward directly to index.php rather than just the root page which does / displays nothing.

Here are all my current container tags: (image to make to make it easier to visualize)

Again, I appreciate all the help!

Edit: (the underline /db in the above screenshot is actually /path, just forgot to edit it as such)

[HS] This is the reason i declare traefik rules separated from docker declaration, i can't proprely read the conf you've done without an headache [/HS]

About Strip-prefix, I encountered and error that i never fixed with my rutorrent docker when i'm accessing http://sub.domain.tld/rutorrent, i've a blank page. I'm forced to use http://sub.domain.tld/rutorrent/ with a slash to the end.

I can't show you cause it's BasicAuth protected but try to add / to the URL.

1 Like

Hey there,

That is exactly what I've been getting as well:

  • :x:https://sub.domain.tld/path
  • :white_check_mark:https://sub.domain.tld/path/
  • :white_check_mark:https://sub.domain.tld/path/index.php

I assume there has to be some / or * somewhere that I'm missing to make the application directly accessible on the /path endpoint without having to add a / (so /path/) after to get it to work. It's a small inconvenience but something I'd like to figure out nether less eventually.

At least for now, I can access the container interface directly without too many issues on a /path/, I'd just eventually like to figure out how to get to it using just /path.

Thanks again!

I apologize for the Docker labels rather than the config, I'm in the reverse position where I struggle to understand the config explantations and am much more confident with understanding and setting up the labels for the containers themselves as I understand what each line does directly. :rofl:

1 Like

Is there any fix for this? I have the same Problem....

  phpmyadmin:
    image: arm64v8/phpmyadmin:latest
    environment:
      - PMA_HOST=db
      - TZ=Europe/Berlin
      - PMA_ABSOLUTE_URI=xxxxxxxxx/phpmyadmin/
    depends_on:
      - db
    networks:
      - traefik_web
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.phpmyadmin.rule=Host(`xxxx.xxxxxx.de`) && PathPrefix(`/phpmyadmin`)"
      - "traefik.http.routers.phpmyadmin.middlewares=phpmyadmin-stripprefix"
      - "traefik.http.middlewares.phpmyadmin-stripprefix.stripprefix.prefixes=/phpmyadmin"

You usually can not place a web app at a path of your choice, as most of them have paths hard-coded for redirects, scripts, images and links.

It only works when you can configure the application itself with some kind of "base path".