Hiding sub path

hi,

i'm new to traefik.

i'm trying to do something basic, that i already do with nginx.

i have a subdomain, let's call it sub.domain.com.
i have a backend server, where an application (redmine, with bitnami on windows) is served at http://192.168.33.246:3003/service.

my problem is the following : i can access sub.domain.com/service but i can't get sub.domain.com directly pointing to 192.168.33.246:3003/service, even if loadbalancer server have /service in his url.

i may be missing something... tried for more than 3 hours, and i didn't find any solution...

thanks ! :slight_smile:

Hello @boscorelly and thanks for your interest in Traefik!

The path configured in a load balancer server URL has no effect, as described in the documentation. To add a prefix to the request received by the client, it is possible to leverage the AddPrefix middleware.

By the way, to have the proxied application working, the resource's path returned by Redmine should not contain the /service (some base path configuration might be needed in the application).

Hope this helps!

1 Like

hi kevin :slight_smile:

thanks for your answer !

i tried with addprefix, stripprefix, and it ends each time without it working.
there is already a reverse proxy with apache which is not needing /service to work.
when i call http://192.168.33.246:3003, i have this : Not Found: /
it works if i add /service to the url.

here is my apache configuration :

Alias /service/ "C:/BitNami/rubystack-1.9.3-13/apps/redmine_service/htdocs/public/"
Alias /service "C:/BitNami/rubystack-1.9.3-13/apps/redmine_service/htdocs/public"

ProxyPass /service balancer://redmineservicecluster/service
ProxyPassReverse /service balancer://redmineservicecluster/service

i want to do the same but... with traefik :smiley:
maybe i'm wrlongly using traefik as not really a reverse proxy ?

(je m'exprime peut-etre mal aussi en anglais ahah)

Here is an example using docker-compose leveraging the addprefix middleware:

version: "3.9"
services:
  traefik:
    image: traefik:v2.5.2
    command:
      - --api.insecure
      - --log.level=debug
      - --providers.docker.exposedByDefault=false

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

    ports:
      - "8080:8080"
      - "80:80"

  whoami:
    image: traefik/whoami
    labels:
      - traefik.enable=true
      - traefik.http.routers.whoami.rule=Host(`whoami.localhost`)
      - traefik.http.routers.whoami.middlewares=add-service-prefix
      - traefik.http.middlewares.add-service-prefix.addprefix.prefix=/service

Then, when a request is made with curl like curl http://whoami.localhost/path the response (which returns the request sent) is the following:

Hostname: fb5a885d9338
IP: 127.0.0.1
IP: 172.20.0.2
RemoteAddr: 172.20.0.3:47414
GET /service/path HTTP/1.1
...

And as expected the requested path is /service/path.

Is it the behavior you are looking for?

hi,

it seems that this is adding the /service in the url, plus i get a 404. in my case, i don't want /service to appear at any time in the url

http://192.168.33.252/service/login?back_url=http%3A%2F%2F192.168.33.252%2Fservice%2F
Page not found
The page you were trying to access doesn't exist or has been removed.

Back

Hello,

The example adds the /service path to the request forwarded to the backend (not to the client request). This means that if a request is sent to http://sub.domain.com/foo, the backend request will be sent to http://192.168.33.246:3003/service/foo.

If this is not the expected behavior,
could you provide an example (docker-compose) or try to explain your problem again?

i want to only use sub.domain.com (local ip address will act the same) and i dont want /service to appear at any time, like i can do with nginx :slight_smile: