Skip to content

Latest commit

 

History

History
 
 

rewrites

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Rewrites Support

You can configure NGINX to rewrite the URI of a request before sending it to the application. For example, /tea/green can be rewritten to /green.

Syntax

To configure URI rewriting you need to add the nginx.org/rewrites annotation to your Ingress resource definition. The annotation syntax is as follows:

nginx.org/rewrites: "serviceName=service1 rewrite=rewrite1[;serviceName=service2 rewrite=rewrite2;...]"

Example

In the following example we load balance two applications that require URI rewriting:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: cafe-ingress
  annotations:
    nginx.org/rewrites: "serviceName=tea-svc rewrite=/;serviceName=coffee-svc rewrite=/beans/"
spec:
  rules:
  - host: cafe.example.com
    http:
      paths:
      - path: /tea/
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee/
        backend:
          serviceName: coffee-svc
          servicePort: 80

Below are the examples of how the URI of requests to the tea-svc are rewritten (Note that the /tea requests are redirected to /tea/).

  • /tea/ -> /
  • /tea/abc -> /abc

Below are the examples of how the URI of requests to the coffee-svc are rewritten (Note that the /coffee requests are redirected to /coffee/).

  • /coffee/ -> /beans/
  • /coffee/abc -> /beans/abc