Blocked by CORS Policy - S3 Bucket Access from Django App Blocked by CORS Policy - S3 Bucket Access from Django App nginx nginx

Blocked by CORS Policy - S3 Bucket Access from Django App


I eventually configured a CloudFront distribution with whitelisted Access-Control-Allow-Origin, with the origin as S3, and configured nginx to include the right headers.

The Origin request header indicates where a fetch originates from. It doesn't include any path information,but only the server name (e.g. https://www.example.com).See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin for details.

Here we set the value that is included in the Access-Control-Allow-Origin response header. If the origin is one of our known hosts--served via HTTP or HTTPS--we allow for CORS. Otherwise, we set the "null" value, disallowing CORS.

map $http_host $cors_origin {default "null";  "~*^\.example\.com$" "$http_x_forwarded_proto://$http_host";}