Important note

The EdgeRules feature is available only on Enterprise plans.

  1. Background

    By running a full site cache or to simply keep track of visits to your CDN side, you need a way to pass the visitor’s IP address back to the origin server where you would grab it. So the first question is how do you pass the IP if the CDN files are cached (do not contact origin server until the files expire)?

    Easy! Choose or create one small file that will never be cached, and use it as a carrier of the visitor’s IP address.

    The second question is which header to use? Our Nginx servers support the X-Forwarded-For header so all we need is a two directive rule, and this can be setup as follows below:

  2. Resulting Nginx Configuration Block

          location ^~ /allpresent_file.css {
                    proxy_set_header X-Forwarded-For $remote_addr;
                    proxy_no_cache 1;
          ...
          }
          
  3. Playground

    If your configuration uses a custom setting or the old configuration with a previous CDN provider requires usage of a different header convention/name, you can still use the existing EdgeRule. Just make sure to rename X-Forwarded-For to your custom header, for example User-IP.

  4. Resulting Nginx Configuration Block

          location ^~ /allpresent_file.css {
                    proxy_set_header User-IP $remote_addr;
                    proxy_no_cache 1;
          ...
          }