HTTP -> HTTPS for a specific URL, only?

Slightly more verbose way to ask: Is there any way to make Traefik not forward HTTP -> HTTPS for a specific URL, only (while continuing to forward the rest to HTTPS)?

I'm going to switch from nginx if I can do this on traefik. Do you know if it is possible? And if so, then how? I've been trying with nginx here: jwilder/nginx-proxy#1340

I saw told by your GitHub bot to ask here in the forum instead:

Hello,

yes it's possible.

Just need to create a router with an entry point on the port 80 and set a priority if needed.

It's hard to say more without any concrete context.

(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)

letsencrypt can me managed by traefik it-self https://docs.traefik.io/v2.0/https/acme/

Is there a traefik docker-compose.yml you recommend that is widely used and supported?
Not many seem to be using traefik-library-image (on github) in comparison to jwilder's nginx-proxy - any idea why? Maybe the primary recommendation for traefik is not to run in docker, but on the host? Also, do you know the equivalent of VIRTUAL_HOST=thedomainname.com for traefik? It makes it quite easy & nice to run multiple webserver on the same host within containers.
Thanks again!

Hi @TrafikJam, first of all, Traefik has an official Docker image, which the recommended way to run it when using Docker. You can find more on the documentation: https://docs.traefik.io/v2.0/getting-started/install-traefik/#use-the-official-docker-image . The Github repository you mention, traefik-library-image is absolutely not aimed to be used by end users: it's the source of truth for the official Docker Image.

There is no docker-compose.yml that would work out of the box for you, as the context is different for each user. You strongly should take time to read the blog post mentioned earlier, and/or the official documentation to fully understand how it works.

1 Like

OK, mostly done switching over to Traefik from Nginx. Now how do I rewrite http://mydomain.com/specificURL1 from container A, to https://service.mydomain.com/specificURL2 which is in container B?

The solution must be compatible with:

      # global redirect to https
      - "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
      - "traefik.http.routers.http-catchall.entrypoints=web"
      - "traefik.http.routers.http-catchall.middlewares=redirect-to-https"

      # middleware redirect
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"

which is working well for me overall.

EDIT: to be extra clear - this needs to be a rewrite, only server-side, not client side, will work.

OK, I put in another few hours trying to figure this out. I see the POST on the URL, but it doesn't make its way to the right services somehow. I've tried using internal container@docker and also external URLs as the 'traefik.http.middlewares.old.replacepathregex.replacement='.

- "traefik.http.middlewares.PP-redirect.replacepathregex.regex=^http://www.domain.com/oldURL"
- "traefik.http.middlewares.PP-redirect.replacepathregex.replacement=http://services.domain.com/new"

I've tried these as labels in the service running "http://www.domain.com/oldURL" the service running "http://services.domain.com/new" - and also both simultaneously. I've also tried it in the global config... And it does still seem like I would have to disable the global HTTPS redirect.

@dduportal @ldez Is there any way to pay for support on this issue? It is really holding me up.
Thank you.

Turns out I cannot afford TraefikEE for $5k/yr :frowning:
I'm testing some router priority settings now...

It seems the request does not get to the right container. The URL POSTs, but not on the right container@docker. It says "-" instead.

Pretty disappointed about this. I thought the forum would have more than one or two people capable of answering such questions. I regret the time switching from nginx to traefik not realizing traefik refuses to even clarify terminology about its functionality. And directed to get support for way more than I can afford... Of course with no guarantee the problem would get solved.

EDIT: I have figured out the nginx config that I want to translate into traffic terms.

the solution of the initial issue (skip the rediection for a specific URL) is here:

  • set a low priority on the global redirect.
  • then set a high priority on the "HTTP only" router

It doesn't work. I get 200s but the service never receives it.
How can I receive on HTTP by a backend service running on HTTPS, and then have it answer on HTTP again?

If you provide more concrete context (docker-compose file), the answer will be more precise.

Working sample:

  traefik:
    # ...

    labels:
    # ...

    # global redirect to https
    traefik.http.routers.http-catchall.rule: hostregexp(`{host:.+}`)
    traefik.http.routers.http-catchall.entrypoints: web
    traefik.http.routers.http-catchall.middlewares: redirect-to-https
    # traefik.http.routers.http-catchall.priority: 1

    # ...

  myapp:
    labels:
    # ...

    traefik.http.routers.app.rule: host(`yourdomain.com`)
    traefik.http.routers.app.entrypoints: web
    traefik.http.routers.app.priority: 100000000000000000000

    # ...

Sure, and I can paste the entire compose file if needed:

services:
    container_name: Services
    restart: always
    ports:
      - "2001:2001"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.services.rule=Host(`services.URL.com`)"
      - "traefik.http.routers.services.entrypoints=websecure"
      - "traefik.http.routers.services.middlewares=services@docker,redirect"
      - "traefik.http.middlewares.services.compress=true"
      - "traefik.http.routers.services.tls.certresolver=le"
      - "traefik.http.routers.services.tls=true"
      - "traefik.http.services.services.loadbalancer.server.port=2001"
      - "traefik.http.middlewares.redirect.replacepathregex.regex=^http://www.URL.com/path/123"
      - "traefik.http.middlewares.redirect.replacepathregex.replacement=https://services.URL.com/456"

"https://services.URL.com/456" does not receive the POST sent to "http://www.URL.com/path/123" - however, I see a 200 in Traefik.
Also, this will not allow "https://services.URL.com/456" to reply to the remote without SSL.
So Traefik needs to sit between it and the remote and remove the SSL somehow.

This is not the only app in the compose file. Another app listens on www.URL.com & URL.com, but I'm not sure if that matters (I tried this replacepath as a label on both apps, either app, and also globally under traefik app).

@ldez :pray: I hope that's enough info

The router is on services.URL.com so it will never catch http://www.URL.com/path/123.

You have to create a router that match the host www.URL.com.

Sorry but what you are trying to do is not clear.

So I will give you an example related to what I understand.

I renamed the elements in your sample, because uses the name services for everything is a really confusing.

Also you don't need to export the port 2001.

services:
  my_app:
    image: myimage
    container_name: my_app
    restart: always
    labels:
      - "traefik.enable=true"

      # router for services.URL.com on the entrypoint websecure
      # https://services.URL.com
      - "traefik.http.routers.app.rule=Host(`services.URL.com`)"
      - "traefik.http.routers.app.entrypoints=websecure"
      - "traefik.http.routers.app.middlewares=comp"
      - "traefik.http.routers.app.tls=true"
      - "traefik.http.routers.app.tls.certresolver=le"

      - "traefik.http.services.app_svc.loadbalancer.server.port=2001"

      # router for http://www.URL.com on the entrypoint web, always redirect.
      # https://www.URL.com/path/123 -> https://services.URL.com/456
      - "traefik.http.routers.app_redirect.rule=Host(`www.URL.com`) && PathPrefix(`/path/123`)"
      - "traefik.http.routers.app_redirect.entrypoints=web"
      - "traefik.http.routers.app_redirect.middlewares=redirect"

      # Middlewares defintions

      - "traefik.http.middlewares.comp.compress=true"
      
      - "traefik.http.middlewares.redirect.redirectregex.regex=^http://www.URL.com/path/123"
      - "traefik.http.middlewares.redirect.redirectregex.replacement=https://services.URL.com/456"