How to redirect http to https in nomad

How to I redirect all http to https i.e. all traffic to http://example.com should get redirected to https://example.com.

My current nomad job tags look like this

                tags = [
                    "traefik.enable=true",
                    "traefik.http.routers.app.rule=Host(`app.example.com`)",
                    "traefik.http.routers.app.entrypoints=http,https",
                    "traefik.http.routers.app.tls=true",
                    "traefik.http.routers.app.tls.certresolver=letsencrypt",
                    "traefik.http.routers.app.tls.domains[0].main=*.example.com",
					"traefik.http.middlewares.test-redirectscheme.redirectscheme.scheme=https",
					"traefik.http.middlewares.test-redirectscheme.redirectscheme.permanent=true"
                ]

I have added the last 2 tags for redirection but it is not working.

You forgot to assign the created middleware to the router:

"traefik.http.routers.app.middlewares=test-redirectscheme"

You could do a global redirect on entrypoint directly, see simple Traefik example.

Note that normally main and sans is used for LetsEncrypt TLS:

"traefik.http.routers.app.tls.domains[0].main=example.com",
"traefik.http.routers.app.tls.domains[0].sans=*.example.com",

@bluepuma77 after adding

"traefik.http.routers.app.middlewares=test-redirectscheme"

i am getting this as error

"traefik.http.routers.app.middlewares=test-redirectscheme"

What error?

From the Docker doc:

services:
     my-container:
       # ...
       labels:
         # Declaring a middleware
         - traefik.http.middlewares.my-redirect.redirectscheme.scheme=https
         # Referencing a middleware
         - traefik.http.routers.my-container.middlewares=my-redirect

Hey, sorry I did not paste the error.

middleware "test-redirectscheme@nomad" does not exist

This is the error.

Looks valid according to the reference.