gunicorn not serving static files

天大地大妈咪最大 提交于 2019-12-07 04:26:30

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/13947326/gunicorn-not-serving-static-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!