Skip to content

Commit

Permalink
add(redirect): how to
Browse files Browse the repository at this point in the history
* ref to redirects
* how to in NAIS

Co-authored-by: Sindre Rødseth Hansen <[email protected]>
Co-authored-by: Carl Hedgren <[email protected]>
  • Loading branch information
3 people committed Nov 13, 2024
1 parent 6bd7709 commit a5ff66f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/workloads/application/explanations/expose.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ This allows for routing traffic to only specific parts of your application, or a
:dart: Learn how to [expose your application with an ingress](../how-to/expose.md).

:books: See the [ingress reference](../reference/ingress.md) for technical details and options.

## Ingress redirects

In some cases, you may want to redirect traffic from one domain to another.
This can be useful if you have changed the domain of your application, or if you want to redirect users from an old domain to a new one.

:dart: Learn how to [redirect traffic with an ingress](../how-to/redirect.md).

:books: See the [ingress reference](../reference/ingress.md#ingress-redirects) for technical details and options.
55 changes: 55 additions & 0 deletions docs/workloads/application/how-to/redirect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
tags: [ application, how-to, redirect ]
---

# Redirect a client

To redirect traffic from one domain to another, you need to define an ingress for the old domain that redirects to the
new domain, with [`.spec.redirects[]`](../reference/application-spec.md#redirects).

The `redirects` field specifies URL redirects. It is structured as a mapping from a source URL to a target URL.

A successful redirect will return a `302 Moved Temporarily` HTTP status code with location header set to the target URL.

!!! note "Status code"
The status code can not be overridden.

### Structure

```yaml hl_lines="4-5" title=".nais/app.yaml"
apiVersion: nais.io/v1alpha1
kind: Application
spec:
ingress:
- https://<MY-SUBDOMAIN-OLD>.<ENVIRONMENT-DOMAIN>
redirects:
- from: https://<MY-SUBDOMAIN-OLD>.<ENVIRONMENT-DOMAIN>
to: https://<MY-SUBDOMAIN>.<ENVIRONMENT-DOMAIN>
```
### Parameters
- **from**: *(string)* The source URL to be redirected. This is the URL where requests originate.
- **to**: *(string)* The target URL for the redirection. This is the URL where requests will be forwarded.
### Usage Example
```yaml hl_lines="4-5" title=".nais/app.yaml"
apiVersion: nais.io/v1alpha1
kind: Application
spec:
ingress:
- https://example-old.com
redirects:
- from: "http://example-old.nais.io"
to: "http://example.nais.io"
```
!!! warning "Redirect restrictions"
The `from` and `to` URLs must be valid URLs.
The `from` URL must be a valid URL that is exposed by the application.

In this example:

- Requests to `http://example-old.nais.io` are redirected to `http://example.nais.io`.
8 changes: 7 additions & 1 deletion docs/workloads/application/reference/ingress.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ spec:
In the example above, only `path1` and `path2` are routed to the application including any sub-paths. All other paths may return a `404` error. Please keep in mind that no path stripping is done as part of the routing and the full path is passed to the application.

## Ingress redirects

[ingress redirects](../explanations/expose.md#ingress-redirects) is a way to perform redirects in NAIS.

Ingress redirects are used to redirect traffic from one domain to another. This can be useful when you want to change the domain of an application or when you want to redirect traffic from an old domain to a new one.

## Ingress customization

Ingresses are automatically created for your application when you specify them in your [application manifest](application-spec.md).
Expand Down Expand Up @@ -267,4 +273,4 @@ Here are some suggestions depending on what http status code you might recieve f
nginx.ingress.kubernetes.io/proxy-body-size: "256M" # copied from annotations
nginx.ingress.kubernetes.io/proxy-buffer-size: "8k" # copied from annotations
nginx.ingress.kubernetes.io/proxy-read-timeout: "300" # copied from annotations
```
```

0 comments on commit a5ff66f

Please sign in to comment.