Nginx 入口控制器不会保持 url 超过重定向

Nginx ingress controller doesn't keep url over redirect

我正在尝试设置一个 nginx 入口控制器;这是入口的 yaml:

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

当我点击 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 时。

在这种情况下,如何保留原始 url?

更新 #1

现在我可以通过创建两个入口来提供静态文件,例如:

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

还有一个

[...]
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

我认为在这种情况下您需要删除注释:

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

此注释使入口重写 http://IP/discover-service/css/file.csshttp://IP/eureka/css/file.css