简体   繁体   English

Django nginx 不提供静态文件

[英]django nginx not serving static files

I am depploying django using nginx and gunicorn.我正在使用 nginx 和 gunicorn 部署 django。 When I access the website I get the following errors.当我访问该网站时,出现以下错误。

 open() "/home/x/aroundu/core/static/static/rest_framework/js/default.js" failed

it's accessing static files wrong, because the path should be like this它访问静态文件是错误的,因为路径应该是这样的

 open() "/home/x/aroundu/core/core/static/rest_framework/js/default.js" failed
server {
    listen 80;

    location /static/ {
        alias /home/x/aroundu/core/core/static/;
    }

    location /media/ {
        alias /home/x/aroundu/core/media/;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')


MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = "/media/"

This should be:这应该是:

location /static/ {
    root /home/x/aroundu/core/core/;
}

location /media/ {
    root /home/x/aroundu/core/;
}

Also for static you have /core/core/ and for media you have only /core/.同样对于静态你有 /core/core/ 而对于媒体你只有 /core/。 I don't know which is the right one, but given your settings they should be the same.我不知道哪个是正确的,但考虑到您的设置,它们应该是相同的。

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

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