# Redirect to HTTPS on custom entrypoint

**URL:** <https://community.traefik.io/t/redirect-to-https-on-custom-entrypoint/24298>\
**Category:** Traefik v2\
**Tags:** tcp, middleware, docker\
**Created:** [September 4, 2024, 9:00am UTC](https://community.traefik.io/t/redirect-to-https-on-custom-entrypoint/24298 "2024-09-04T09:00:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AshleyChan](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@AshleyChan](https://community.traefik.io/u/AshleyChan)\
**Post date:** [September 4, 2024, 9:00am UTC](https://community.traefik.io/t/redirect-to-https-on-custom-entrypoint/24298/1 "2024-09-04T09:00:00Z")

</div>

Hi everyone,

I am trying to serve a http service on port 8080. but It only works when I go to `https://localhost:8080` but doesn't work when I go to `http://localhost:8080`. What I want is to forward the http traffic that comes in to 8080 to https protocol.  
So that when I visit `http://localhost:8080`, It would still get a response.

Here's a minimal code of what I'm trying to do -

```yaml
services:
  traefik:
    command:
      - "--providers.docker"
      - "--entrypoints.customweb.address=:8080"
      - "--log.level=DEBUG"
    depends_on:
      - whoami
    image: traefik:v2.11
    ports:
      - mode: host
        published: 8080
        target: 8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  whoami:
    image: traefik/whoami
    labels:
      - traefik.http.routers.whoami.entrypoints=customweb
      - traefik.http.routers.whoami.rule=Host(`localhost`)
      - traefik.http.routers.whoami.tls=true
      - traefik.http.routers.whoami.service=whoami
      - traefik.http.services.whoami.loadbalancer.server.port=80

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [September 4, 2024, 9:04am UTC](https://community.traefik.io/t/redirect-to-https-on-custom-entrypoint/24298/2 "2024-09-04T09:04:12Z")

</div>

That should simply work with RedirectScheme midleware ([doc](https://doc.traefik.io/traefik/middlewares/http/redirectscheme/)).

---

<div class="post-metadata">

**Author:** ![AshleyChan](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@AshleyChan](https://community.traefik.io/u/AshleyChan)\
**Post date:** [September 4, 2024, 9:14am UTC](https://community.traefik.io/t/redirect-to-https-on-custom-entrypoint/24298/3 "2024-09-04T09:14:53Z")

</div>

Redirect middleware seem not to work.

It's redirecting `https://localhost:8080` to `https://localhost:443`

```yaml
services:
  traefik:
    command:
      - --providers.docker
      - --entrypoints.customweb.address=:8080
      - --log.level=DEBUG
    depends_on:
      - whoami
    image: traefik:v2.11
    ports:
      - mode: host
        published: 8080
        target: 8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  whoami:
    image: traefik/whoami
    labels:
      - traefik.http.routers.whoami.entrypoints=customweb
      - traefik.http.routers.whoami.rule=Host(`localhost`)
      - traefik.http.routers.whoami.tls=true
      - traefik.http.routers.whoami.service=whoami
      - traefik.http.services.whoami.loadbalancer.server.port=80
      - traefik.http.middlewares.redirect-mw.redirectscheme.scheme=https
      - traefik.http.middlewares.redirect-mw.redirectscheme.permanent=true
      - traefik.http.routers.whoami.middlewares=redirect-mw

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [September 4, 2024, 9:16am UTC](https://community.traefik.io/t/redirect-to-https-on-custom-entrypoint/24298/4 "2024-09-04T09:16:43Z")

</div>

The documentation is your friend:

> **`port`**  
> The `port` option defines the port of the new URL.

---

<div class="post-metadata">

**Author:** ![AshleyChan](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@AshleyChan](https://community.traefik.io/u/AshleyChan)\
**Post date:** [September 4, 2024, 9:33am UTC](https://community.traefik.io/t/redirect-to-https-on-custom-entrypoint/24298/5 "2024-09-04T09:33:04Z")

</div>

I added the port but that didn't work either.

I still get -

```bash
curl -Lk http://localhost:8080
404 page not found

```

```yaml
services:
  traefik:
    command:
      - --providers.docker
      - --entrypoints.customweb.address=:8080
      - --log.level=DEBUG
    depends_on:
      - whoami
    image: traefik:v2.11
    ports:
      - mode: host
        published: 8080
        target: 8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  whoami:
    image: traefik/whoami
    labels:
      - traefik.http.routers.whoami.entrypoints=customweb
      - traefik.http.routers.whoami.rule=Host(`localhost`)
      - traefik.http.routers.whoami.tls=true
      - traefik.http.routers.whoami.service=whoami
      - traefik.http.services.whoami.loadbalancer.server.port=80
      - traefik.http.middlewares.redirect-mw.redirectscheme.scheme=https
      - traefik.http.middlewares.redirect-mw.redirectscheme.permanent=true
      - traefik.http.middlewares.redirect-mw.redirectscheme.port=8080
      - traefik.http.routers.whoami.middlewares=redirect-mw

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [September 4, 2024, 10:00am UTC](https://community.traefik.io/t/redirect-to-https-on-custom-entrypoint/24298/6 "2024-09-04T10:00:21Z")

</div>

Ok, maybe it doesn't work anymore. It works with `http` when you remove `tls`. I know that people where complaining that you could do a `http` connection even though `tls` was enabled.

Here we go ([doc](https://doc.traefik.io/traefik/routing/routers/#general)):

> When a TLS section is specified, it instructs Traefik that the current router is dedicated to HTTPS requests only (and that the router should ignore HTTP (non TLS) requests).

---

<div class="post-metadata">

**Author:** ![AshleyChan](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@AshleyChan](https://community.traefik.io/u/AshleyChan)\
**Post date:** [September 4, 2024, 10:01am UTC](https://community.traefik.io/t/redirect-to-https-on-custom-entrypoint/24298/7 "2024-09-04T10:01:45Z")

</div>

Yes, I also reached similar conclusion, maybe it doesn't work.

I tried a lot and finally ended up in forum as last resort! 🙂

Thank you!
