Tuesday, February 7, 2023

proxy_pass vs. rewrite in nginx ingress controller

 

proxy_pass rewrite
Return 200 with the content 302 with the URL to the redirected page
Content To nginx, then the client Second call skips nginx; returned through the redirect URL directly to client

Example of proxy_pass:

location /testing {
  proxy_pass https://news.yahoo.com/us;
}

Example of rewrite:

rewrite ^/(.*)$ https://www.newurl.com/$1-$http_x_header1 redirect
How to hook up them to nginx conf?

Add them as annotations to the Ingress. One example is:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress-name
  annotations:
    nginx.org/mergeable-ingress-type: "master"
    nginx.org/server-snippets: |
      rewrite ....
      location /testing {
        ....
      }
spec:
  ....


Annotation of nginx.org/rewriters:

nginx.org/rewriters: "serviceName=my-service-name rewrite=/my-new-endpoint"