gpt4 book ai didi

nginx入口子路径重定向

转载 作者:行者123 更新时间:2023-12-02 02:58:42 24 4
gpt4 key购买 nike

我有一个入口 Controller 和入口资源,其中所有/devops 都映射到后端的 devopsservice。当我尝试点击“http://hostname/devops ”时,一切正常,我得到一个页面(尽管没有 CSS 和样式),其中包含一组超链接,例如其中一个是“日志”。

当我单击“日志”超链接时,它会将我重定向到 http://hostname/logs而我需要它是 http://hostname/devops/logs .

知道我能做什么吗?

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
namespace: ingress-nginx
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/add-base-url : "true"
spec:
rules:
- host: master1.dev.local
http:
paths:
- backend:
serviceName: devops1
servicePort: 10311
path: /devops

最佳答案

看起来您的入口没有提供任何服务/devops/*。尝试添加具有相同后端的另一个路径 /devops/* 。基本上是这样的:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
namespace: ingress-nginx
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/add-base-url : "true"
spec:
rules:
- host: master1.dev.local
http:
paths:
- backend:
serviceName: devops1
servicePort: 10311
path: /devops/*
- backend:
serviceName: devops1
servicePort: 10311
path: /devops

更新:以上已deprecated赞成这样的事情:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: rewrite
namespace: default
spec:
rules:
- host: master1.dev.local
http:
paths:
- backend:
serviceName: devops1
servicePort: 10311
path: /devops(/|$)(.*)

关于nginx入口子路径重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53089294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com