Pus*_*ots 6 nginx kubernetes nginx-ingress
我已经阅读文档一千次,但我仍然不明白我将如何使用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
Run Code Online (Sandbox Code Playgroud)
应用程序根
创建带有 app-root 注释的 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: /
Run Code Online (Sandbox Code Playgroud)
检查重写是否有效
$ 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
Run Code Online (Sandbox Code Playgroud)
它只是在内部将请求重定向'/'
到不同的路径。如果您的应用程序的根路径不同于'/'
.
例如,假设您的应用程序正在侦听'/server'
,您可以将 Nginx 注释设置为:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/app-root: /server
Run Code Online (Sandbox Code Playgroud)
此时,任何传入请求example.com/
都将使用 HTTP 状态代码 302 重定向,以指示资源在哪里:example.com/server
。
使用nginx.ingress.kubernetes.io/app-root: /destination
注释将添加以下几行nginx.conf
if ($uri = /) {
return 302 $scheme://$http_host/destination;
}
Run Code Online (Sandbox Code Playgroud)
这意味着它将指示浏览器重定向(302暂时移至)路径/destination
。正如其他人所说,这里没有进行内部重写。
如果您希望在用户访问根路径时将其重定向到默认位置,则该注释非常有用:/
归档时间: |
|
查看次数: |
4439 次 |
最近记录: |