Important note

The EdgeRules feature is available only on Enterprise plans.

Using a platform where you have a Webserver that serves your main Website with images, css, js and other static assets and one server only for your media (video) files, makes CDN usage less user-friendly. This is because you need to have two zones set with different Origin URLs in order to cover both servers, plus a good solution to switch URL rewriting between these two zones.

We want to make sure that we will meet certain conditions when caching files from both servers individually. By condition, you can consider above example with website and separate media server. Below is how you can distinguish two different origin servers by using a condition and directive called PROXY PASS:

  1. Multiple rules

    Create multiple rules for multiple conditions and include PROXY PASS directive to navigate to appropriate back end.

    Note that before you pass the request to origin, you need to modify request header accordingly.

    The disadvantage of this approach is that you need to manage multiple rules, however, if you have other directives you plan to use alongside with PROXY PASS, this may be a better solution for that use case.

    NGINX Configuration block

             location ~ \.(mp4|m4a|m4v|mov|flv)$ {
                        proxy_set_header Host domain.com;
             ...
                        proxy_pass http://111.111.111.111$request_uri;
             ...
             }
             
  2. Single Rule

    You can use single rule with multiple conditions in order to match appropriate URi and navigate to back end URL accordingly.

    Note that before you pass the request to origin, you need to modify request header accordingly.

    NGINX Configuration Block

          location / {
                     set $origin_host domain.com;
                     set $origin http://123.321.231.132;
                if ($request_uri ~ \.(mp4|m4a|m4v|mov|flv)$) {
                     set $origin_host media.domain.com;
                     }
                if ($request_uri ~ \.(mp4|m4a|m4v|mov|flv)$) {
                     set $origin http://111.111.111.111;
                     }
                     proxy_set_header Host $origin_host;
          ...
                     }
          

Important Note

Note that you are not limited to two origin URL’s only, above patterns can be applied to multiple back ends.