Skip to content

Configure Your Origin With NGINX

The Flink OTT Client SDK will slightly alter the way how client devices request data from your CDN. Instead of typical HTTP GET calls, they will use HTTP Range Requests 🔗.

Please Note: The correct setup of your infrastructure may depend on both your streaming origin's configuration and/or your CDN's configuration. For example, some CDNs pass through all HTTP headers they receive from the origin while other CDNs add, remove or replace existing HTTP headers. To ensure the correct setup, please keep in mind that some CDN providers can override or alter your origin HTTP headers. This means, that in some cases, Step 1 and Step 2 of this guide can interfere with each other.

General Requirements

Modern web and streaming servers support range requests by default. However, you might want to ensure that your streaming origin / CDN meets the following requirements:

CORS OPTIONS Request Support

CORS Preflight requests (HTTP OPTIONS requests) must be supported. Verification: curl -i -X OPTIONS <your manifest URL> must contain an ALLOWED header in which OPTIONS must be listed.

Example:

curl -X OPTIONS http://example.org -i

HTTP/1.1 204 No Content
Allow: OPTIONS, GET, HEAD, POST

HTTP Range Request Support

HTTP Range Requests 🔗 must be allowed. This means, when sending a CORS OPTIONS request, your server must respond with a Access-Control-Allowed-Headers header in which Range must be listed.

Example:

curl -X OPTIONS http://example.org -i

HTTP/1.1 204 No Content
Access-Control-Allowed-Headers: Range

NGINX Configuration

Step 1 - Update Configuration File

Add the following to your nginx.conf. You can find your config at <installation-path>/conf.

# find location in server section
location / {
    # --- CORS begin ---

    # CORS OPTIONS
    if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Allow-Headers' 'Range' always;
        add_header 'Access-Control-Allow-Methods' 'GET, HEAD, OPTIONS' always;
        add_header 'Content-Length' 0;
        return 204;
    }

    # CORS HEAD
    if ($request_method = 'HEAD') {
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length' always;
    }

    # CORS GET
    if ($request_method = 'GET') {
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length, Content-Range' always;
    }

    # --- CORS end ---
}

Next Steps

The next step is to configure your CDN 🔗.