I have nginx running in a container behind Traefik, and I'm trying to redirect any http to https using Traefik middleware.
If I browse to https://domain-name/website-name
I can see my container, but if I browse to http://domain-name/website-name
, I get a 404 error.
Below is my config file for website-name:
http:
routers:
entrypoints:
- web
- web-secure
tls: true
rule: "PathPrefix(`/website-name`)"
middlewares:
- "http-redirect"
service: "website-name"
middlewares:
http-redirect:
regex: "http://domain-name/(.*)"
replacement: "https://domain-name/$1"
services:
website-name:
loadBalancer:
servers:
- url: http://website-name:80
Why won't http redirect to https with this setup? It only recognizes https.
For example if I change the http-redirect
code to:
http-redirect:
redirectRegex:
regex: "https://domain-name/(.*)"
replacement: "https://$1?test"
This works and redirects https://domain-name/website-name
to https://domain-name/website-name?test
, but for some reason http won't work.
http://domain-name/website-name
gives me a 404 error. And, it is not a 404 error produced by nginx. So it is not even routing to the container.