Traefik routing issues

Hi, I am actually wanting to deploy a GLPI service in my traefik managed docker platform. Traefik is working fine with normal containers as reverse proxy, but I want to set up a GLPI container using path labels, my labels are as follows:

  - traefik.enable=true
  - traefik.docker.network=nginx-proxy
  - traefik.port=80
  - traefik.frontend.redirect.regex=^(.*)/glpi$$
  - traefik.frontend.redirect.replacement=$$1/glpi/
  - traefik.frontend.rule=HostRegexp:{subdomain:mysubdomain}.mydomain.com;PathPrefix:/glpi;ReplacePathRegex:^/glpi/(.*) /$$1
  - traefik.entrypoint=https

When I hit https://mysubdomain.mydomain.com/glpi I am correctly routed to my GLPI container, but CSS is broken, and al loaded code on the browser targets to mysubdomain.mydomain.com (without the path).

Is it any way to make the path routing fully working? Thanks in advance!

Hi @bcantera ! A few questions to help you:

  • Could elaborate on the "broken CSS" errors please? I suppose the HTML answered by the backend application is providing links to the stylesheets/javascripts. What are these links exactly? absolute? relative?
  • Is there a particular reason that you are not using PathPrefixStrip as the frontend rule (instead of the combination of Path + ReplacePathRegex ? Is it working with a PrefixPath?
  • Could you provide a reproduction case (is there a glpi docker container for example), so we can reproduce the issue locally and help you
    ?

Hi @dduportal, you are right, by broken CSS I mean that the backend gives me links of the resource without the site path at the end.

Here it is a reproduction example with a generic domain, a valid domain must be used to reproduce the situation:

version: "3.4"

services:

#GLPI Container
  glpi:
    container_name: glpi
    depends_on:
      - mysql
    image: diouxx/glpi
    expose:
      - 80
    restart: always
    labels:
      - traefik.enable=true
      - traefik.docker.network=nginx-proxy
      - traefik.port=80
      - traefik.frontend.redirect.regex=^(.*)/glpi$$
      - traefik.frontend.redirect.replacement=$$1/glpi/
      - traefik.frontend.rule=HostRegexp:{subdomain:mysubdomain}.mydomain.com;PathPrefix:/glpi;ReplacePathRegex:^/glpi/(.*) /$$1
      - traefik.entrypoint=https

#Mysql Container
  mysql:
    image: mysql:5.7.23
    container_name: mysql
    hostname: mysql
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=glpidb
      - MYSQL_USER=glpi_user
      - MYSQL_PASSWORD=glpi
    labels:
      - "traefik.enable=false"

networks:
  default:
    external:
      name: nginx-proxy

Hi @bcantera, thanks for these elements.

I was able to reproduce; it looks like that GLPI is not built for supporting hosting behind a context by default.
As you figured out, the HTML generated by GLPI starts with /xxxx,
(exemple <script type="text/javascript" src="/lib/jquery/js/jquery.min.js?v=9.4.3"></script>),
which are assuming the webapp is always served under the root path of the website (aka. /).

I was not able to find any configuration directive for GLPI to make it aware of the path (location/context). But as It's using Apache, you might be able to adapt the configuration with https://httpd.apache.org/docs/2.4/mod/core.html#location maybe (haven't done Apache for years so I won't be able to chime in here).

For information, whatever reverse-proxy will cause the same problem here, unless you are able to modify the body of the HTTP response on the go (and bye bye performances with this). So maybe reaching out the forum / issue tracker of GLPI could be a good point to request such a feature (like an environment variable for configuring behind a prefix maybe?)

Understood, issue https://github.com/glpi-project/glpi/issues/6196 is open now on GLPI repo.

1 Like

Hello, after migrating to traefik v2 and testing the same situation, I found out that issue is happening on any backend listening on "/", here is an example with wordpress to reproduce the same scenario shown with glpi:

version: "3.4"

services:
  wordpress:
    container_name: blog
    image: wordpress
    restart: always
    environment:
      WORDPRESS_DB_PASSWORD: (password)
    labels:
      - traefik.http.routers.bla.rule=(Host(`domain.tld`) && Path(`/blog`))
      - traefik.http.routers.bla.tls=true
      - traefik.http.routers.bla.tls.certresolver=lets-encrypt
      - traefik.http.routers.bla.middlewares=app1-stripprefix
      - traefik.http.middlewares.app1-stripprefix.stripprefix.prefixes=/blog        
      - traefik.http.middlewares.app1-stripprefix.stripprefix.forceSlash=false
      - traefik.port=80
    networks:
      - internal
      - web
    volumes:
      - wp_data:/var/www/html
    depends_on:
      - mysql

  mysql:
    container_name: db
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: (password)
    networks:
      - internal
    labels:
      - traefik.enable=false
    volumes:
      - db_data:/var/lib/mysql

networks:
  web:
    external: true
  internal:
    external: false

volumes:
  wp_data:
  db_data:

When I got to domain.tld/blog the request gets fine to wordpress container but the content served by wordpress is set on domain.tld on any response. Since wordpress is working on / it seems logical.

Maybe the strip prefix of middlewares is not aimed to be used this way?
Is there an way to use traefik to access a webservice on "/" when typing on the browser "domain.tld/blog"?

Cheers

We provide specialized sanitizing services to Office Home Car Gym Hotel Studio Spa Hospital Shop/ Super Market Society Building/ Township & Commercial properties.
Regards https://www.ggmservices.in/