[英]Django Gunicorn not load static files
i'm trying to deploy my django project with gunicorn and nginx, but i need some help. 我正在尝试用gunicorn和nginx部署我的django项目,但我需要一些帮助。 when i code gunicorn myproject.wsgi:application I manage to see my website in the localhost page but without any css.
当我编码gunicorn myproject.wsgi:应用程序我设法在localhost页面看到我的网站,但没有任何CSS。 Why gunicorn does not load my css files that are into the static folder of my project?
为什么gunicorn不加载我的项目的静态文件夹中的css文件?
Guinicorn_start script: https://dpaste.de/TAc4 Gunicorn output: https://dpaste.de/C6YX Guinicorn_start脚本: https ://dpaste.de/TAc4 Gunicorn输出: https ://dpaste.de/C6YX
Gunicorn will only serve the dynamic content, ie the Django files. Gunicorn只会提供动态内容,即Django文件。 So you need to setup a proxy server such as nginx to handle the static content (your CSS files).
因此,您需要设置代理服务器(如nginx)来处理静态内容(您的CSS文件)。 I assume you are starting Gunicorn the right way, so you just need to configure nginx to serve the static files.
我假设你正在以正确的方式启动Gunicorn,所以你只需要配置nginx来提供静态文件。 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 即使设置了此配置,也必须调用“./manage.py collectstatic”来使css正常工作
Gunicorn is only responsible for serving the django aspect of your site. Gunicorn只负责为您网站的django方面提供服务。
The static files need to be served by nginx. 静态文件需要由nginx提供。 See: How exactly do I server static files with nginx and gunicorn for a Django app?
请参阅: 如何为Django应用程序使用nginx和gunicorn服务器静态文件? .
。 This should be configured in the
nginx.conf
file. 这应该在
nginx.conf
文件中配置。 If you post it here we can have a look at it. 如果你在这里发布,我们可以看看它。
I have got this issue before. 我以前遇到过这个问题。 Try set static path in your Nginx configuration then grant permission of your project.
尝试在Nginx配置中设置静态路径,然后授予项目权限。
sudo chmod -R 777 /webapps/yourweb/
Try starting your server again. 尝试再次启动服务器。 Hope it help.
希望它有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.