NginX
/Apache HTTPD
work every well in VM world. If your deployment environment use container technologies like Docker
and Kubernetes
, it become bulky and hard to config.
Recently, I discovered a lighter alternative solution call whitenoise
-
Install
or, add it into requirements.txt
whitenoise~=4.1
-
add WhiteNoise
to the MIDDLEWARE_CLASSES
list
# settings.py
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...
]
Note: WhiteNoiseMiddleware
must be above all other middleware apart from Django’s SecurityMiddleware
.
-
Configs STATIC_ROOT
# settings.py
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
-
And you still need collect statics files
python manage.py collectstatic
That's it. Now you can run whatever app server you want, somethings like:
python manage.py runserver
# or
gunicorn YOUR_APP.wsgi # change YOUR_APP to your real app