Closed chrisdevereux closed 2 years ago
@conatus @janbaykara fyi
Nice one for finding this.
In this PR we added AWS_S3_ENDPOINT_URL
to the mix in order to begin serving from the CDN, as MEDIA_URL
(which was set to the CDN on StopWatch but seemingly ignored) doesn't appear to be taken up. Suspect we may have to do this trick here also, but hopefully it should just work with MEDIA_URL
.
The great thing is once this is solved, we've solved it. Maybe one for a short blog post!
you're right, AWS_S3_CUSTOM_DOMAIN is the right one. MEDIA_URL is apparently only used by django's default storage so not helpful here. Where we went wrong before is that the signed url didn't work on the cdn until we changed AWS_S3_ADDRESSING_STYLE.
Cool!
For the record I think the library calling the variable AWS_S3_CUSTOM_DOMAIN
is absolutely heading down a silly path. Why call it this when it is about CDNs, typically Cloudfront presumably on AWS? It is even how the documentation talks about it. Anyway, now we know!
https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#cloudfront
We'll also need to update MEDIA_URL in the app settings to point to the cdn-enabled spaces url.
As a reminder, the reason using the cdn is particuarly important is that it runs over cloudflare, so (unlike the IP of a DO spaces bucket) if an ISP were to carelessly IP-block it (as virgin media currently are), it would also break the entire internet. So they'd actually fix it.
From: https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html
From https://docs.digitalocean.com/products/spaces/how-to/enable-cdn/