django权限错误/admin/fonts/Roboto-Regular-webfont.woff

问题描述 投票:0回答:2

我得到权限错误。我的 docker 容器上的 /admin/fonts/Roboto-Regular-webfont.woff 权限被拒绝。我通过命令 docker exec -it container /bin/bash 进入 docker 容器并运行 curl -XGET 'http://localhost' 得到这个错误它在行上显示错误 {% stylesheet 'style' %在我的 base.html 上。 docker 在 aws 上的 ubuntu 机器里面。我正在使用 nginx 和 uwsgi 运行这个应用程序。 uwsgi.ini 中的 uid 和 gid 是 www-data。请帮我解决这个问题。

请查找 docker 日志

root@ip-10-252-14-11:/home/ubuntu/workarea/sourcecode/ntdl/ntdl# docker logs 
ntdl

> [email protected] start-prod /home/ntdl/code
> concurrently --no-color "uwsgi --ini /home/ntdl/code/uwsgi.ini" "nginx" 
 "npm run render-prod"

[0] [uWSGI] getting INI configuration from /home/ntdl/code/uwsgi.ini
[2]
[2] > [email protected] render-prod /home/ntdl/code
[2] > babel-node node/react-render.jsx
[2]
[2] React render server listening at http://0.0.0.0:9009
[2] *****  app. post
[2] Warning: Accessing PropTypes via the main React package is deprecated, 
and will be removed in  React v16.0. Use the latest available v15.* prop- 
types package from npm instead. For info on usage, compatibility, migration 
and more, see 
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets []
[2] global ntdl - react render - url http://54.252.92.17/api/search
[2] AJAX Failed: Error: connect ECONNREFUSED 54.252.92.17:80
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets []
[2] *****  app. post
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets []
[2] global ntdl - react render - url http://54.252.92.17/api/search
[2] AJAX Failed: Error: connect ECONNREFUSED 54.252.92.17:80
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets []
[2] *****  app. post
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets []  
[2] global ntdl - react render - url http://54.252.92.17/api/search
[2] AJAX Failed: Error: connect ECONNREFUSED 54.252.92.17:80
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets []
[2] *****  app. post
[2] advancedFacets - constructor - props [] 
[2] _updateProps []
[2] render advanced Facets - facets []
[2] global ntdl - react render - url http://54.252.92.17/api/search
[2] AJAX Failed: Error: connect ECONNREFUSED 54.252.92.17:80
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets []
[2] *****  app. post
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets [] 
[2] global ntdl - react render - url http://54.252.92.17/api/search
[2] AJAX Failed: Error: connect ECONNREFUSED 54.252.92.17:80
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets []
[2] *****  app. post
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets []
[2] global ntdl - react render - url http://54.252.92.17/api/search
[2] AJAX Failed: Error: connect ECONNREFUSED 54.252.92.17:80
[2] advancedFacets - constructor - props []
[2] _updateProps []
[2] render advanced Facets - facets []

嗨 Gasman,您可以看到权限错误 实际上,roboto 字体文件在该路径下可用。其次它在 {% stylesheet 'style' %} 抛出错误 请告诉我会出现什么问题。

非常感谢, 巴拉特AK

django amazon-web-services ubuntu docker wagtail
2个回答
1
投票

发生这种情况是因为您(大概)在 Amazon S3 上托管字体。从远程域加载字体时,当前的浏览器需要有效的 CORS HTTP 标头。

如果您正在使用

storages.backends.s3boto.S3BotoStorage
后端,您可以通过将以下行添加到您的设置文件来添加适当的标头:

AWS_HEADERS = {
    'Access-Control-Allow-Origin': '*'
}

并重新运行

./manage.py collectstatic
。有关详细信息,请参阅http://docs.wagtail.io/en/v2.1/advanced_topics/deploying.html#cloud-storage


0
投票

这是一个很老的话题,但我为此苦苦挣扎了一段时间,所以我把我的发现留在这里。

我的问题发生在用我的 Django 应用程序重建 docker 镜像后,问题是缺乏文件权限

/vol/web/static/admin/fonts/Roboto-Bold-webfont.woff
.
最后是缺少对整个 Docker 命名卷文件夹的权限:

services:
    my_app:
        volumes:
            static_data:/vol/web
...

volumes:
    static_data:

我终于设法通过删除卷挂载目录的内容(之前对其进行备份,在我的例子中位于此处:

/var/lib/docker/volumes/my_app_static_data/_data/
)并允许 Docker 重新创建该卷来使其工作。 我不知道它是怎么发生的,但我的整个卷目录都属于一些奇怪的
opc
用户和组,而不是我的普通用户。

可能运行简单:

sudo chown my_user:my_user /var/lib/docker/volumes/my_app_static_data/_data

也会做这份工作。

© www.soinside.com 2019 - 2024. All rights reserved.