小编Bri*_*bot的帖子

Nginx 在 Digital Ocean 上的 Django 应用程序中访问静态文件时引发 403 Forbidden

在我的系统上完成了本地开发的 django 项目后,我按照 Digital Ocean 教程在此处部署了 django 应用程序Digital Ocean Django ASGI 设置教程

我根据教程配置了gunicorn,并且所有测试和确认都通过了但是当我从其公共IP地址加载我的网站时,该网站加载时没有任何样式或设计,也没有图像......就像纯文本一样(只是html内容)

我的nginx配置如下

server {
    listen 80;
    server_name XXX.XX.XXX.XX;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        alias /home/username/projectdir/staticfiles;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的 django 项目设置如下(有关静态设置的部分)

# The absolute path to the directory where collectstatic will collect static files for deployment.
STATIC_ROOT  = BASE_DIR / 'staticfiles'

# The URL to use when referring to static files (where …
Run Code Online (Sandbox Code Playgroud)

django nginx django-staticfiles

5
推荐指数
1
解决办法
3282
查看次数

标签 统计

django ×1

django-staticfiles ×1

nginx ×1