简体   繁体   English

gunicorn不提供静态文件

[英]gunicorn not serving static files

I've been working on serving a Django app from an Ubuntu server. 我一直在努力从Ubuntu服务器上提供Django应用程序。 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. 我已经按照http://senko.net/en/django-nginx-gunicorn/中的所有说明进行操作,但是当我进入gunicorn_django -b 0.0.0.0:8000步骤时,该站点突然停止提供静态文件。 The site works just fine using the dev server python manage.py runserver 0.0.0.0:8000 . 使用开发服务器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 在遵循了本教程的其余部分以及Andrew Gorcester的建议之后 ,我添加了一个

location /static {
     root /path/to/static/files;
}

to my nginx sites-available file, and everything seems to be working! 到我的nginx sites-available文件,一切似乎都正常!

Gunicorn is not a general-purpose web server, all it does is serve an application (django in this case). Gunicorn不是通用的Web服务器,它所做的只是为应用程序提供服务(本例中为Django)。 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. 为了开发人员的方便,django除了在开发过程中不提供静态文件,因为它不是提供静态文件的有效或必不可少的工具。

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. 如果您一直按照说明进行操作,系统将指示您设置在端口80上运行的nginx,这将1)将您的应用程序从端口8000代理到端口80,以及2)在同一端口上提供静态文件,然后选择执行该操作每个请求(基于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. 静态文件在端口8000上不起作用不会引起警报-在此配置下,只有正确配置nginx后,它们才应在端口80上起作用。 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. django还有其他可能的配置以及其他用于服务静态文件的策略,尽管在大多数情况下,大多数情况下都遵循建议的服务静态文件的惯例,这种情况与本应用程序完全分开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM