我已经阅读了1000遍文档,但是我仍然不明白如何使用nginx.ingress.kubernetes.io/app-root
注释。
有人可以用简单的英语提供示例+说明吗?
文档:https://kubernetes.github.io/ingress-nginx/examples/rewrite/
我还可以复制粘贴整个文本;没那么多。
nginx.ingress.kubernetes.io/app-root Defines the Application Root that the Controller must redirect if it's in '/' context string
应用程序根
创建带有应用程序根注释的Ingress规则:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/app-root: /app1
name: approot
namespace: default
spec:
rules:
- host: approot.bar.com
http:
paths:
- backend:
serviceName: http-svc
servicePort: 80
path: /
检查重写是否正常
$ curl -I -k http://approot.bar.com/
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.11.10
Date: Mon, 13 Mar 2017 14:57:15 GMT
Content-Type: text/html
Content-Length: 162
Location: http://stickyingress.example.com/app1
Connection: keep-alive
答案 0 :(得分:0)
它只是内部redirects requests coming to '/'
to a different path。如果您应用程序的根路径与'/'
不同,这将很有用。
例如,假设您的应用程序正在'/server'
中监听,您可以将Nginx注释设置为:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/app-root: /server
这时,example.com/
处的所有传入请求都将在内部进行重写以进入example.com/server
,从而使您的应用程序可以侦听它们,而不必显式指定传入的'/'
请求。
答案 1 :(得分:0)
使用nginx.ingress.kubernetes.io/app-root: /destination
批注将在nginx.conf
if ($uri = /) {
return 302 $scheme://$http_host/destination;
}
这意味着它将指示浏览器将(临时移动的302)重定向到路径/destination
。正如其他人所说,这里没有内部重写。
如果您有一个默认位置,当用户点击根路径时,要将用户重定向到该默认位置,则注释非常有用:/