首页 > 解决方案 > 无法访问 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/;
    }

标签: djangoamazon-web-servicesnginxamazon-s3

解决方案


推荐阅读