k8s中nginx-ingress配置总结

mtain 2022年05月26日 152次浏览

nginx-ingress配置清单

https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/nginx-configuration/configmap.md

一、显示真实IP

nginx的body大小限制,报错:<html>\r\n<head><title>413 Request Entity Too Large</title></head>\r\n<body>\r\n<center><h1>413 Request Entity Too Large</h1></center>\r\n<hr><center>nginx/1.17.10</center>\r\n</body>\r\n</html>

nginx.ingress.kubernetes.io/proxy-body-size: 500m

image-1667216485250

二、显示真实IP

在k8s的nginx-ingress日志中显示访问的真实IP

1. 修改ConfigMap:nginx-configuration

compute-full-forwarded-for: "true"
forwarded-for-header: X-Forwarded-For
use-forwarded-headers: "true"

image-1653494968512

2. 重新部署nginx-ingress-controller

image-1653495052145

三、 隐藏Nginx版本

1. 修改ConfigMap:nginx-configuration

server-tokens: "false"

2. 重新部署nginx-ingress-controller