django - 无法访问 AWS S3 上的静态文件
问题描述
在 django 项目中,我使用 Nginx 访问放置在 AWS S3 上的静态文件。成功完成命令后collectstatic
,样式仍然不适用于项目。当我在浏览器中激活调试器时,我可以看到对静态文件的请求在正确的路径上,但它们无法访问
(index):18 GET https://mysite-staging.s3.amazonaws.com/static/admin/css/icons.css net::ERR_ABORTED 403 (Forbidden)
(index):37 GET https://mysite-staging.s3.amazonaws.com/static/lifeline/css/global.css net::ERR_ABORTED 403 (Forbidden)
(index):24 GET https://mysite-staging.s3.amazonaws.com/static/material/js/jquery.js net::ERR_ABORTED 403 (Forbidden)
我如何访问它?您是否需要为此更改 Nginx 设置?我当前的 nginx 配置
location /s3/ {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Authorization '';
proxy_set_header Host mysite-staging.s3.amazonaws.com;
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_hide_header x-amz-meta-server-side-encryption;
proxy_hide_header x-amz-server-side-encryption;
proxy_hide_header Set-Cookie;
proxy_ignore_headers Set-Cookie;
proxy_intercept_errors on;
add_header Cache-Control max-age=31536000;
proxy_pass https://mysite-staging.s3.amazonaws.com/;
}
解决方案
推荐阅读
- typescript - 为什么我不能使用索引类型推断写入对象属性
- javascript - 如何使用 Amcharts 3 从 Legend 中隐藏阈值?
- firebase - 如何使用 firebase 为以下案例构建数据?
- angular - Angular 测试 - 使用 rxjs switchMap 的链式 HTTP 请求
- python - 数据帧到 MongoDB
- java - stream.distinct() 返回非不同元素
- node.js - 如何在 Sequelize 中查找值来自关联表的所有查询?
- reactjs - 表单复选框动画不起作用,但表单确实起作用
- javascript - 如何在 ionic 应用程序中将 zoomhome 插件添加到传单地图?
- javascript - Symfony 4.4 - Summernote 编辑器将 base64 图像上传到服务器