我在几个nodejs服务前面坐着一个NGINX Ingress。我希望将路径/graphql限制为仅发布内容类型=application/json
我添加了以下注释,它似乎在限制方面有效,但是有效的请求现在返回404
nginx.ingress.kubernetes.io/server-snippet: |
location /graphql {
limit_except OPTIONS POST {
deny all;
}
if ($http_content_type != "application/json") {
return 403;
}
}发布于 2022-03-10 08:23:52
我认为问题在于,您的location {}块没有像nginx入口中定义的规则路径那样的上游路径。从ingress-nginx-controller pod获取nginx入口配置:
$ kubectl exec -n your-ingress-nginx-namespace ingress-nginx-controller-xxx-xxx -- cat /etc/nginx/nginx.conf并检查其他位置{}块,以查找/graphql位置{}配置可能需要的内容。
以下基本nginx.ingress.kubernetes.io/server-snippet适用于我(除了POST和content=application/json返回403状态代码以外的请求,有效请求是可以的):
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cms-ingress-service
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/server-snippet: |
location /graphql {
limit_except OPTIONS POST {
deny all;
}
if ($http_content_type != "application/json") {
return 403;
}
set $proxy_upstream_name "default-nginx-80";
proxy_pass http://upstream_balancer;
}
spec:
...另外,要注意如果是邪恶..。在位置上下文中使用时。
因此,我建议您在投入生产之前彻底测试您的最终配置。
https://stackoverflow.com/questions/71393786
复制相似问题