Merge pull request #3174 from Shopify/rewrite-regex
Generalize Rewrite Block Creation and Deprecate AddBaseUrl (not backwards compatible)
This commit is contained in:
commit
71cc6df74f
11 changed files with 71 additions and 396 deletions
|
|
@ -57,11 +57,11 @@ spec:
|
|||
paths:
|
||||
- path: /foo/bar
|
||||
backend:
|
||||
serviceName: test
|
||||
serviceName: service1
|
||||
servicePort: 80
|
||||
- path: /foo/bar/
|
||||
backend:
|
||||
serviceName: test
|
||||
serviceName: service2
|
||||
servicePort: 80
|
||||
```
|
||||
|
||||
|
|
@ -79,14 +79,14 @@ spec:
|
|||
paths:
|
||||
- path: /foo/bar/.+
|
||||
backend:
|
||||
serviceName: test
|
||||
serviceName: service3
|
||||
servicePort: 80
|
||||
```
|
||||
|
||||
The ingress controller would define the following location blocks, in order of descending length, within the NGINX template for the `test.com` server:
|
||||
|
||||
```txt
|
||||
location ~* "^/foo/bar/.+\/?(?<baseuri>.*)" {
|
||||
location ~* ^/foo/bar/.+ {
|
||||
...
|
||||
}
|
||||
|
||||
|
|
@ -101,13 +101,12 @@ location ~* "^/foo/bar" {
|
|||
|
||||
The following request URI's would match the corresponding location blocks:
|
||||
|
||||
- `test.com/foo/bar/1` matches `~* "^/foo/bar/.+\/?(?<baseuri>.*)"`
|
||||
- `test.com/foo/bar/` matches `~* "^/foo/bar/"`
|
||||
- `test.com/foo/bar` matches `~* "^/foo/bar"`
|
||||
- `test.com/foo/bar/1` matches `~* ^/foo/bar/.+` and will go to service 3.
|
||||
- `test.com/foo/bar/` matches `~* ^/foo/bar/` and will go to service 2.
|
||||
- `test.com/foo/bar` matches `~* ^/foo/bar` and will go to service 1.
|
||||
|
||||
**IMPORTANT NOTES**:
|
||||
|
||||
- paths created under the `rewrite-ingress` are sorted before `\/?(?<baseuri>.*)` is appended. For example if the path defined within `test-ingress-2` was `/foo/.+` then the location block for `^/foo/.+\/?(?<baseuri>.*)` would be the LAST block listed.
|
||||
- If the `use-regex` OR `rewrite-target` annotation is used on any Ingress for a given host, then the case insensitive regular expression [location modifier](https://nginx.org/en/docs/http/ngx_http_core_module.html#location) will be enforced on ALL paths for a given host regardless of what Ingress they are defined on.
|
||||
|
||||
## Warning
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ You can add these Kubernetes annotations to specific Ingress objects to customiz
|
|||
|
||||
|Name | type |
|
||||
|---------------------------|------|
|
||||
|[nginx.ingress.kubernetes.io/add-base-url](#rewrite)|"true" or "false"|
|
||||
|[nginx.ingress.kubernetes.io/app-root](#rewrite)|string|
|
||||
|[nginx.ingress.kubernetes.io/affinity](#session-affinity)|cookie|
|
||||
|[nginx.ingress.kubernetes.io/auth-realm](#authentication)|string|
|
||||
|
|
@ -29,7 +28,6 @@ You can add these Kubernetes annotations to specific Ingress objects to customiz
|
|||
|[nginx.ingress.kubernetes.io/auth-url](#external-authentication)|string|
|
||||
|[nginx.ingress.kubernetes.io/auth-snippet](#external-authentication)|string|
|
||||
|[nginx.ingress.kubernetes.io/backend-protocol](#backend-protocol)|string|HTTP,HTTPS,GRPC,GRPCS,AJP|
|
||||
|[nginx.ingress.kubernetes.io/base-url-scheme](#rewrite)|string|
|
||||
|[nginx.ingress.kubernetes.io/canary](#canary)|"true" or "false"|
|
||||
|[nginx.ingress.kubernetes.io/canary-by-header](#canary)|string|
|
||||
|[nginx.ingress.kubernetes.io/canary-by-cookie](#canary)|string|
|
||||
|
|
@ -126,10 +124,6 @@ Currently a maximum of one canary ingress can be applied per Ingress rule.
|
|||
In some scenarios the exposed URL in the backend service differs from the specified path in the Ingress rule. Without a rewrite any request will return 404.
|
||||
Set the annotation `nginx.ingress.kubernetes.io/rewrite-target` to the path expected by the service.
|
||||
|
||||
If the application contains relative links it is possible to add an additional annotation `nginx.ingress.kubernetes.io/add-base-url` that will prepend a [`base` tag](https://developer.mozilla.org/en/docs/Web/HTML/Element/base) in the header of the returned HTML from the backend.
|
||||
|
||||
If the scheme of [`base` tag](https://developer.mozilla.org/en/docs/Web/HTML/Element/base) need to be specific, set the annotation `nginx.ingress.kubernetes.io/base-url-scheme` to the scheme such as `http` and `https`.
|
||||
|
||||
If the Application Root is exposed in a different path and needs to be redirected, set the annotation `nginx.ingress.kubernetes.io/app-root` to redirect requests for `/`.
|
||||
|
||||
!!! example
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue