Configure Nginx for aws s3 static and media files Configure Nginx for aws s3 static and media files nginx nginx

Configure Nginx for aws s3 static and media files


In case of S3, nginx is not responsible for serving static and media files and you no need to configure anything.


In Nginx try with:

location /static {       alias /path/to/your/static;    }

In Djando settings.py use:

STATIC_ROOT = '/path/to/your/static'STATIC_URL = '/static/'

After this you need to collect statics in the folder, run the following command:

python manange.py collectstatic

Django will save all static files in the path specified, now Nginx will load the static files without the URL


In case you are using app server to serve the static files,then you need to configure nginx the way mattia has mentioned.

However you don't really need the same if you are using s3 path. Based on your configuration when your run collectstatic it should automatically sync your files on s3.

In you views you use the s3 , to have performance boost you can put your s3 behind Cloudfront and server content from there.