.. _cloud-storage: Configuring cloud storage ========================= .. index:: storage, S3, Cloud Storage, Azure Storage If you generated the project with a cloud provider, static files and user uploads are served from that provider's object storage rather than from your application server. This is independent of the platform you deploy to, so follow this page alongside the deployment guide of your choice. How the template uses your bucket --------------------------------- A single bucket (or container, on Azure) holds both kinds of files, under two prefixes: - ``static/``: the output of ``collectstatic``, meant to be **publicly readable**. - ``media/``: user uploads, served through ``MEDIA_URL``. The storages do **not** set a per-object ACL on upload. Uploaded objects simply inherit whatever access rules the bucket has, so making static files reachable is a one-off bucket configuration step, described below for each provider. This matches the current default of all three providers, which is to disable per-object ACLs in favour of bucket-wide policies. .. warning:: The instructions below deliberately expose only the ``static/`` prefix. Granting public read on the whole bucket also exposes ``media/``, and since the template sets unsigned URLs for media, every user upload would then be readable by anyone able to guess its URL. See `Keeping media private`_ if uploads in your project are not meant to be public. Amazon S3 --------- New buckets have ACLs disabled (*Object Ownership: bucket owner enforced*) and all four **Block Public Access** settings enabled. You need to relax the two policy-related ones, then attach a bucket policy scoped to the ``static/`` prefix. .. code-block:: bash BUCKET=your-bucket-name # Outside of us-east-1, add: # --create-bucket-configuration LocationConstraint=$AWS_REGION aws s3api create-bucket --bucket $BUCKET --region us-east-1 # Allow public *policies*, while still blocking public ACLs aws s3api put-public-access-block --bucket $BUCKET \ --public-access-block-configuration \ "BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=false,RestrictPublicBuckets=false" cat > /tmp/static-policy.json <