Using multiple origins to serve different assets from separate zones is not ideal in terms of SEO and CDN utilization. In this article, we will cover the use of multiple origins on the same zone with the goal of utilizing the CDN more efficiently.
The EdgeRules feature is available only on Enterprise plans.
We want to make sure that we will meet certain conditions when caching files from both servers individually. In this example, we will be serving a website at the origin and separate server as the media server. Below, we can distinguish the two different origin servers by using a condition and directive called PROXY PASS
:
Creating the Rule : Multiple Conditions
Create multiple rules for multiple conditions and include PROXY PASS
directive to navigate to appropriate back end.
Note that before the request is passed to the origin, the request header must be modified accordingly.
The disadvantage of this approach is that multiple rules must be managed, however, if other directives will be used alongside 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;
...
}
Creating The Rule: Multiple Conditions With One Rule
A single rule may be used with multiple conditions in order to match appropriate URI and navigate to back end URL accordingly.
Note that before the request is passed to the origin, the request header must be modified 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;
...
}
These rules are not limited to two origin URLs only, above patterns can be applied to multiple back ends.
We hope this article was helpful and as always, If there are any questions or concerns about any of the topics mentioned in this article, please feel free to reach out to support - we are available 24/7 by chat or email!