Nginx ingress controller doesn't keep url over redirect

10/1/2018

I am trying to setup a nginx ingress controller; here is the yaml of the ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-rules
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "false"

spec:
  rules:
  - host: 
    http:
      paths:
      - path: /discover-service
        backend:
          serviceName: discover-service
          servicePort: discover-port

When I hit http://IP/discover-service it shows an HTML without CSS and JS. As I can see, they are looked under http://IP/eureka/css/file.css instead of http://IP/discover-service/css/file.css.

How can I preserve the original url in this case?

UPDATE #1

Now I can serve the static files by creating two ingresses like:

ingress-rules-discover-root.yaml

[..]
metadata:
  name: ingress-rules-discover-root

  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    [...]

spec:
  rules:
  - host: 
    http:
      paths:

      - path: /discover-service
        backend:
          serviceName: discover-service
          servicePort: discover-port

and another one

[...]
metadata:
  name: ingress-rules-discover-path
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    [...]

spec:
  rules:
  - host: 
    http:
      paths:
      - path: /eureka
        backend:
          serviceName: discover-service
          servicePort: discover-port
-- Justin
kubernetes
kubernetes-ingress
nginx
nginx-reverse-proxy

1 Answer

10/1/2018

I believe in this case you need to remove the annotation:

nginx.ingress.kubernetes.io/rewrite-target: /

This annotation makes the ingress rewrite http://IP/discover-service/css/file.css to http://IP/eureka/css/file.css

-- Rico
Source: StackOverflow