Skip to content

fix: Make NGINX use X-Forwarded-For headers

Stan Hu requested to merge sh-enable-nginx-x-forwarded-for into main

When using Kubernetes and nginx-ingress, the first X-Forwarded-For IP is an internal IP instead of the client IP. This is because the nginx-ingress controller is deployed as a load balancer in front of the application, and it adds its own IP address as the first X-Forwarded-For header before passing along the request along.

To fix this issue, configure the nginx-ingress controller to use the client IP address as the first X-Forwarded-For header by setting the use-forwarded-headers annotation to "true". This will cause the controller to use the X-Real-IP and X-Forwarded-For headers that are included in the original request instead of adding its own IP address as the first X-Forwarded-For header.

Ref: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#use-forwarded-headers

Relates to #68 (closed)

Edited by Stan Hu

Merge request reports