Nginx入口控制器不会通过重定向保留网址

时间:2018-10-01 16:17:42

标签: nginx kubernetes nginx-reverse-proxy kubernetes-ingress

我正在尝试设置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时,它显示了没有CSS和JS的HTML。如我所见,它们是在http://IP/eureka/css/file.css下而不是http://IP/discover-service/css/file.css下看的。

在这种情况下,如何保存原始网址?

更新#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

1 个答案:

答案 0 :(得分:2)

我相信在这种情况下,您需要删除注释:

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

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