Django Gunicorn not load static files

你离开我真会死。 提交于 2019-12-17 20:05:23

问题


i'm trying to deploy my django project with gunicorn and nginx, but i need some help. when i code gunicorn myproject.wsgi:application I manage to see my website in the localhost page but without any css. Why gunicorn does not load my css files that are into the static folder of my project?

Guinicorn_start script: https://dpaste.de/TAc4 Gunicorn output: https://dpaste.de/C6YX


回答1:


Gunicorn will only serve the dynamic content, i.e. the Django files. So you need to setup a proxy server such as nginx to handle the static content (your CSS files). I assume you are starting Gunicorn the right way, so you just need to configure nginx to serve the static files. You can use a configuration like the following, where you just need to change the path to your static files:

server {
    listen       80;
    server_name  localhost;

    location / {
        root   html;
        index  index.html index.htm;
        proxy_pass http://127.0.0.1:8000;
    }
    location /static {
        autoindex on;
        alias /path/to/staticfiles;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

Even if this configuration is setup, you have to call "./manage.py collectstatic" to make your css work




回答2:


Gunicorn is only responsible for serving the django aspect of your site.

The static files need to be served by nginx. See: How exactly do I server static files with nginx and gunicorn for a Django app?. This should be configured in the nginx.conf file. If you post it here we can have a look at it.




回答3:


I have got this issue before. Try set static path in your Nginx configuration then grant permission of your project.

sudo chmod -R 777 /webapps/yourweb/

Try starting your server again. Hope it help.



来源:https://stackoverflow.com/questions/20175243/django-gunicorn-not-load-static-files

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