Nginx+uwsgi部署django无法加载静态文件的问题
Nginx和uwsgi都安装好了,测试过,没问题,然后使用uwsgi启动django项目时,使用浏览器查看项目就会出现静态文件无法加载的问题。怎么配置都搞不好,求大神赐教。
nginx的配置,路径是:/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name 192.168.127.128;
charset UTF-8;
access_log /var/log/nginx/SecondSpace_access.log;
error_log /var/log/nginx/SecondSpace_error.log;
location / {
include uwsgi_params;
uwsgi_pass 192.168.127.128:8000;
uwsgi_read_timeout 2;
root /usr/share/nginx/html;
index index.html index.htm;
}
location /static {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /home/dh/PycharmProjects/python/SecondSpace/static;
}
location /media {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /home/dh/PycharmProjects/python/SecondSpace/media;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
然后是uwsgi.ini的配置,路径是:/home/dh/PycharmProjects/python/SecondSpace/uwsgi.ini(SecondSpace时我的项目目录)
[uwsgi]
socket=:8000
chdir =/home/dh/PycharmProjects/python/SecondSpace
module = SecondSpace.wsgi
master=true
processes = 4
vacuum = true
求大神指点,实在没辙了,网上教程看完了。### 问题描述
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
你期待的结果是什么?实际看到的错误信息又是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
nginx访问静态文件和uwsgi是没啥关系的,都是一样的配制方法.无论用gunicorn还是uwsgi都是这么配置.
这是我随手截图的写法,用的是root,
按照alias写法,就要在下边的路径加上/static/
你看看加上尾部的/行不行.
还有就是nginx是否有权限访问你的文件目录的问题.看一下nginx运行的用户是谁
看你配置文件见应该没什么问题,可参考以下几点排查:
希望对你有帮助。
首先确定django的 DEBUG模式为关闭状态
其次确定 Nginx 中有 静态文件的路径并指向正确的系统目录
最后一定要保证 uwsgi 和 Nginx 的关系要配置正确
自从上次自己倒腾完 想写个笔记来着 这才想起来
看nginx日志
access_log /var/log/nginx/SecondSpace_access.log;
error_log /var/log/nginx/SecondSpace_error.log;
还有访问静态文件的url是什么样的