nginx django and cdn integration

Posted March 26, 2017 3.1k views
NginxDjangoUbuntu 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 ?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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.