Reputation: 699
I've been working on serving a Django app from an Ubuntu server. I've followed all of the instructions in http://senko.net/en/django-nginx-gunicorn/, but when I get to the gunicorn_django -b 0.0.0.0:8000
step, the site suddenly stops serving static files. The site works just fine using the dev server python manage.py runserver 0.0.0.0:8000
.
I haven't changed the stock settings for anything. Any ideas why this is not working?
EDIT:
After following the rest of the tutorial and the advice of Andrew Gorcester, I added a
location /static {
root /path/to/static/files;
}
to my nginx sites-available
file, and everything seems to be working!
Upvotes: 6
Views: 5961
Reputation: 19983
Gunicorn is not a general-purpose web server, all it does is serve an application (django in this case). And django does not serve static files except in development, for the convenience of the developer, because it is not an efficient or necessarily secure vehicle for serving static files.
If you follow the instructions all the way through you will be directed to set up nginx running on port 80, which will 1) proxy your application from port 8000 to port 80 and 2) serve static files on the same port, choosing which to do per request based on the URL.
It is not cause for alarm that static files do not work on port 8000 -- under this configuration they should only work on port 80, once nginx is properly configured. There are other possible configurations for django with other strategies for serving static files, although most of them follow the recommended convention of serving static files totally separate from the application like in this case.
Upvotes: 6