Cloudfront + whitenoise: sends 301 redirect to origin
danjac opened this issue · 1 comments
This might be an issue with my Cloudfront setup, but I've followed setup instructions here as much as possible: http://whitenoise.evans.io/en/stable/django.html#use-a-content-delivery-network
- STATIC_URL is set up correctly: https://d2nv40q2zf328u.cloudfront.net/static/
- Set up a distribution pointing to the correct domain: audiotrails.io
- Origin Protocol Policy "Match Viewer"
- Viewer Protocol Policy "HTTP or HTTPS"
- Managed-CachingOptimized Policy (Brotli & gzip enabled)
- Brotli enabled on Whitenoise
- Compress Objects Automatically "Yes"
- Path Pattern "static/*"
Instead of serving the cached files directly Cloudfront redirects (301) back to the original file served through Whitenoise e.g. https://d2nv40q2zf328u.cloudfront.net/static/bundle.css -> https://audiotrails.io/static/bundle.css. Whitenoise then serves the file directly.
I have another distribution set up for an S3 bucket for user-generated media files and this works correctly i.e. no redirect.
Response headers from Cloudfront:
age: 1562
content-length: 162
content-type: text/html
date: Sun, 09 May 2021 12:22:59 GMT
location: https://audiotrails.io:443/static/bundle.css
server: nginx
via: 1.1 7edd8006b8bc56aba6e41686a63bba53.cloudfront.net (CloudFront)
x-amz-cf-id: X8vIu6EOua49uEw0AwfuEL52BmCgNg18mMRmdxCznsE9dd26GG5dng==
x-amz-cf-pop: HEL50-C1
x-cache: Hit from cloudfront
Has anyone else run into this problem?
Closing due to age. I suspect the problem was possibly the web server redirecting HTTP to HTTPS, or CloudFront configruation.