In order to serve static files, as Jamie Hewland says, normally one routes all the requests to /static/ using Nginx
location /static/ {
alias /path/to/static/files;
}
![Nginx + Gunicorn + Django]()
In other words, and as coreyward says about Gunicorn / Unicorn
was not designed to solve the suite of problems involved in serving
files to clients
Same line of reasoning applies if you consider other WSGI server like uWSGI instead of Gunicorn. In uWSGI documentation
it’s inefficient to serve static files via uWSGI. Instead, serve them
directly from Nginx and completely bypass uWSGI
The easier way is to serve your static files with Python using WhiteNoise library which is very easy to setup (you might want to use a CDN so that most requests won't reach the Python app). As Miguel de Matos says, you just have to
Collect static
python manage.py collectstatic
Installing whitenoise
pip install whitenoise
Add the following STATICFILES_STORAGE in settings.py
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
Add the following to your MIDDLEWARE in settings.py (as mracette notes, "According to the whitenoise docs you should place the middleware after django.middleware.security.SecurityMiddleware")
`MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...
]