How to set REMOTE_ADDR from HTTP_X_ORIGINAL_FORWARDED_FOR header when going through EZOIC proxy cache

Prerequisites:

  • kubernetes ingress
  • your varnish proxy cache
  • Symfony PHP application
  1. Edit your global Kubernetes Ingress Config Map in namespace ingress-nginx named nginx-configuration  and add use-forwarded-headers: true

2. In your Varnish proxy in section sub vcl_recvadd

     if (req.http.X-Original-Forwarded-For) {
         set req.http.X-Forwarded-For = req.http.X-Original-Forwarded-For;
     } else {
      set req.http.X-Forwarded-For = client.ip;
     }

3. In you Symfony App define ENV variable  TRUSTED_PROXIES=10.0.0.0/8

Now you will get right user IP from $_SERVER['REMOTE_ADDR']or when you call Request::getClientIp() in your Symfony App.


Another way without other prerequisites

Add this section to your nginx.conf (instead of x-middleton-ip you can use X-Original-Forwarded-For or X-Forwarded-For)

http {
 set_real_ip_from 10.0.0.0/8;
 real_ip_recursive on;
 real_ip_header x-middleton-ip;