How can I exclude certain file types from the CDN?

If you use the creoline CDN exclusively for certain file types (e.g. images, fonts, stylesheets and JavaScript), you can block access to other file types.


Solution

When initially retrieving your resources, the creoline CDN uses a special user agent that you can use for checking.


User agent: Creobot 2.0.1 (+https://www.creoline.com/de/products/content-delivery-network)


You can use this information to block specific HTTP requests from this user agent.


Example for NGINX:

map $http_user_agent $is_creobot {
    default 0;
    ~^Creobot 1;
}

map $uri $is_whitelisted {
    default 0;
    ~*\.(jpg|jpeg|png|gif|webp|avif|css|js|pdf)$ 1;
}

location / {
    if ($is_creobot$is_whitelisted = 10) {
        return 403;
    }

    try_files $uri $uri/ =404;
}


With this config, only URL endings from the whitelist are allowed. Other requests are rejected via 403.


It is still possible to access the file directly without a CDN, only CDN requests are rejected via 403, so that accessing the identical file via the CDN results in a 403 error.