如何设置Ingress-nginx自定义错误 [英] How to set ingress-nginx custom errors
问题描述
我使用kubernetes ingress-nginx控制器和GKE上的一组自定义错误,但是我遇到了一些问题.
I use the kubernetes ingress-nginx controller and a set custom errors on GKE but I have some problems.
目标:
如果something-web-app
中发生50x错误,我将返回HTTP状态代码200和JSON {"status":200, "message":"ok"}
Goal:
If a 50x error occurs in something-web-app
, I'll return the HTTP status code 200 and JSON {"status":200, "message":"ok"}
问题:
-
我已经阅读了自定义错误文档,但没有如何自定义
default-backend
的示例.
I have read the custom-errors document but there is no example of how to customize the
default-backend
.
我不了解ConfigMap和Annotation之间的区别.
I do not understand the difference between ConfigMap and Annotation.
ingress-nginx控制器首先如何工作.
How does ingress-nginx controller work in the first place.
推荐答案
您可以使用两种方式进行操作:
You can do it using two way :
- 在入口中添加注释
- 更改入口控制器configmap(更像beckend)
1 .尝试将此注释添加到kubernetes入口:
1. Try adding this annotation to kubernetes ingress :
nginx.ingress.kubernetes.io/default-backend:nginx-errors-svc
nginx.ingress.kubernetes.io/default-backend: nginx-errors-svc
nginx.ingress.kubernetes.io/custom-http-errors:404,503
nginx.ingress.kubernetes.io/custom-http-errors: 404,503
nginx.ingress.kubernetes.io/default-backend:错误页面
nginx.ingress.kubernetes.io/default-backend: error-pages
如果这样不起作用,请将其与两个一起添加:
If that doesn't work add this along with two :
nginx.ingress.kubernetes.io/server-snippet: |
location @custom_503 {
return 404;
}
error_page 503 @custom_503;
2.编辑配置图
您可以将此配置映射应用于入口控制器
You can apply this config map to ingress controller
apiVersion: v1
kind: ConfigMap
name: nginx-configuration-ext
data:
custom-http-errors: 502,503,504
proxy-next-upstream-tries: "2"
server-tokens: "false"
您还可以引用此博客: https://habr.com/ru /company/flant/blog/445596/
You can also refer this blog : https://habr.com/ru/company/flant/blog/445596/
这篇关于如何设置Ingress-nginx自定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!