nginx django and cdn integration

March 26, 2017 179 views
Nginx Django Ubuntu 16.04

I am running nginx and django on my server, and I have cdn, I setted up cdn but now the issue is how to configure /etc/nginx/sites-available/default
few minutes ago my default file looks like this ->

location /static/ {
root /home/user/env/;

but now I have to change them to successfully pull the static files from cdn, But I could not find any resource for this, can any one help me for this to me ?

1 Answer


Unless you're CDN is different from the majority, most only require that you use either a specific URI that they provide, or a CNAME which masks the URI with your own custom sub-domain. With that in hand, you'd simply link to your static files.

So, for example, if they provide you with a link that looks like:

and you'd normally access your CDN files using:

Then you'd simply link to the static files using the CDN URI instead of your domain, like so (as an example):

You wouldn't actually set this up through NGINX. This is something you setup either in your HTML, CSS, or JS files -- wherever you link to static files.

Have another answer? Share your knowledge.