CDN Mesh Delivery delivery works on top of the origin and CDN of your choice. Use the following tutorial to configure Nginx to work effectively with Mesh Delivery.
What you need to configure
- Enable CORS
-
Allow RANGE & OPTIONS requests
How to do it: in your nginx.conf file
For our application, the configuration of nginx with rtmp-module is done inside the nginx.conf file, found in <installation path>/conf
.
It has two main sections:
- The rtmp section, which for our purposes generates the DASH / HLS live content; and,
- The http section, which delivers over http the content, as any standard web server.
This tutorial will show you what needs to be added to the http section to support OPTIONS and range requests.
An informative section showing how to use the rtmp module to generate live content is available here.
HTTP Section
The http section of nginx.conf defines what the server will make available on HTTP from its filesystem, and how it will be made available (range requests authorization).
Therefore, it will always be the same and does not depend on how the stream is sent or generated.
In our case it has 1 location called /your_location, but you can have separate locations for dash_vod, dash_live, hls_vod, hls_live. In the latter case, you need to replicate the configuration for each location.
In order to allow OPTIONS and range requests, don't forget to add the parameters in the following if loops
:if ($request_method = 'OPTIONS')
if ($request_method = 'GET')
http {
##YOUR nginx.conf
location /your_location{
## your_location configuration
## .....
## end of /your_location configuration
## ---- ADD THIS TO CONFIGURE CORS, OPTIONS and RANGE REQUESTS -----
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
# Custom headers and headers various browsers *should* be OK with but aren't
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
# Tell client that this pre-flight info is valid for 20 days
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
add_header 'Access-Control-Allow-Origin' '*';
return 200;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
}
## -----END OF CORS, OPTIONS, RANGE REQUESTS CONF-------------------
}
}