我需要配置nginx来发送413状态代码的JSON响应。我试过这个:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ .Chart.Name }}-app2
annotations:
kubernetes.io/ingress.class: "nginx"
ingress.kubernetes.io/server-snippet: |
proxy_intercept_errors on;
error_page 413 /413.json;
location /413.json {
return 413 '{"error": {"status_code": 413,"status": "TEST"}}';
}
spec:
tls:
- hosts:
- app2.example.com
secretName: wildcard-tls
rules:
- host: app2.example.com
http:
paths:
- path: /
backend:
serviceName: {{ .Chart.Name }}-app2
servicePort: 80
但没有成功。它仍然返回文本为413 Request Entity Too Large
的html页面。
你能建议如何在kubernetes中配置nginx以在413上返回json吗?
您可以尝试将此片段添加到入口
nginx.ingress.kubernetes.io/server-snippet: |
location @custom_413 {
default_type application/json;
return return 413 '{"error": {"status_code": 413,"status": "TEST"}}';;
}
error_page 413 @custom_413;