traefik/docs/content/middlewares/http/redirectscheme.md

214 lines
4.5 KiB
Markdown
Raw Normal View History

---
title: "Traefik RedirectScheme Documentation"
description: "In Traefik Proxy's HTTP middleware, RedirectScheme redirects clients to different schemes/ports. Read the technical documentation."
---
2019-04-08 15:14:08 +00:00
# RedirectScheme
Redirecting the Client to a Different Scheme/Port
{: .subtitle }
2019-09-10 12:40:05 +00:00
<!--
TODO: add schema
-->
The RedirectScheme middleware redirects the request if the request scheme is different from the configured scheme.
!!! warning "When behind another reverse-proxy"
When there is at least one other reverse-proxy between the client and Traefik,
the other reverse-proxy (i.e. the last hop) needs to be a [trusted](../../routing/entrypoints.md#forwarded-headers) one.
Otherwise, Traefik would clean up the X-Forwarded headers coming from this last hop,
and as the RedirectScheme middleware relies on them to determine the scheme used,
it would not function as intended.
## Configuration Examples
2023-05-10 13:28:05 +00:00
```yaml tab="Docker & Swarm"
2019-04-03 12:32:04 +00:00
# Redirect to https
labels:
2019-09-23 15:00:06 +00:00
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.scheme=https"
2020-02-17 10:04:04 +00:00
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.permanent=true"
2019-04-03 12:32:04 +00:00
```
```yaml tab="Kubernetes"
# Redirect to https
2023-03-20 14:38:08 +00:00
apiVersion: traefik.io/v1alpha1
2019-04-03 12:32:04 +00:00
kind: Middleware
metadata:
name: test-redirectscheme
spec:
redirectScheme:
scheme: https
2020-02-17 10:04:04 +00:00
permanent: true
2019-04-03 12:32:04 +00:00
```
2019-10-15 15:34:08 +00:00
```yaml tab="Consul Catalog"
# Redirect to https
labels:
2020-02-17 10:04:04 +00:00
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.scheme=https"
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.permanent=true"
2019-10-15 15:34:08 +00:00
```
2019-07-22 07:58:04 +00:00
```yaml tab="File (YAML)"
# Redirect to https
http:
middlewares:
test-redirectscheme:
redirectScheme:
scheme: https
2020-02-17 10:04:04 +00:00
permanent: true
2019-07-22 07:58:04 +00:00
```
```toml tab="File (TOML)"
# Redirect to https
[http.middlewares]
[http.middlewares.test-redirectscheme.redirectScheme]
scheme = "https"
permanent = true
```
## Configuration Options
2019-04-03 12:32:04 +00:00
### `permanent`
Set the `permanent` option to `true` to apply a permanent redirection.
2023-05-10 13:28:05 +00:00
```yaml tab="Docker & Swarm"
2020-02-17 10:04:04 +00:00
# Redirect to https
labels:
# ...
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.permanent=true"
```
```yaml tab="Kubernetes"
# Redirect to https
2023-03-20 14:38:08 +00:00
apiVersion: traefik.io/v1alpha1
2020-02-17 10:04:04 +00:00
kind: Middleware
metadata:
name: test-redirectscheme
spec:
redirectScheme:
# ...
permanent: true
```
```yaml tab="Consul Catalog"
# Redirect to https
labels:
# ...
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.permanent=true"
```
```yaml tab="File (YAML)"
# Redirect to https
http:
middlewares:
test-redirectscheme:
redirectScheme:
# ...
permanent: true
```
```toml tab="File (TOML)"
# Redirect to https
[http.middlewares]
[http.middlewares.test-redirectscheme.redirectScheme]
# ...
permanent = true
```
2019-04-03 12:32:04 +00:00
### `scheme`
2021-02-11 13:34:04 +00:00
The `scheme` option defines the scheme of the new URL.
2023-05-10 13:28:05 +00:00
```yaml tab="Docker & Swarm"
2020-02-17 10:04:04 +00:00
# Redirect to https
labels:
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.scheme=https"
```
```yaml tab="Kubernetes"
# Redirect to https
2023-03-20 14:38:08 +00:00
apiVersion: traefik.io/v1alpha1
2020-02-17 10:04:04 +00:00
kind: Middleware
metadata:
name: test-redirectscheme
spec:
redirectScheme:
scheme: https
```
```yaml tab="Consul Catalog"
# Redirect to https
labels:
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.scheme=https"
```
```yaml tab="File (YAML)"
# Redirect to https
http:
middlewares:
test-redirectscheme:
redirectScheme:
scheme: https
```
```toml tab="File (TOML)"
# Redirect to https
[http.middlewares]
[http.middlewares.test-redirectscheme.redirectScheme]
scheme = "https"
```
2019-04-03 12:32:04 +00:00
### `port`
2021-02-11 13:34:04 +00:00
The `port` option defines the port of the new URL.
2020-02-17 10:04:04 +00:00
2023-05-10 13:28:05 +00:00
```yaml tab="Docker & Swarm"
2020-02-17 10:04:04 +00:00
# Redirect to https
labels:
# ...
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.port=443"
```
```yaml tab="Kubernetes"
# Redirect to https
2023-03-20 14:38:08 +00:00
apiVersion: traefik.io/v1alpha1
2020-02-17 10:04:04 +00:00
kind: Middleware
metadata:
name: test-redirectscheme
spec:
redirectScheme:
# ...
2020-05-14 15:30:06 +00:00
port: "443"
2020-02-17 10:04:04 +00:00
```
```yaml tab="Consul Catalog"
# Redirect to https
labels:
# ...
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.port=443"
```
```yaml tab="File (YAML)"
# Redirect to https
http:
middlewares:
test-redirectscheme:
redirectScheme:
# ...
2020-05-14 15:30:06 +00:00
port: "443"
2020-02-17 10:04:04 +00:00
```
2020-05-14 15:30:06 +00:00
```toml tab="File (TOML)"
# Redirect to https
[http.middlewares]
[http.middlewares.test-redirectscheme.redirectScheme]
# ...
port = 443
```
2020-05-14 15:30:06 +00:00
!!! info "Port in this configuration is a string, not a numeric value."