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
求大神指点,实在没辙了,网上教程看完了。### 问题描述
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
nginx访问静态文件和uwsgi是没啥关系的,都是一样的配制方法.无论用gunicorn还是uwsgi都是这么配置.
这是我随手截图的写法,用的是root,
按照alias写法,就要在下边的路径加上/static/
你看看加上尾部的/行不行.
还有就是nginx是否有权限访问你的文件目录的问题.看一下nginx运行的用户是谁