Hi again, everyone,
I wanted to follow up on my previous post and share that I’ve made some progress.
What’s working now
- User uploads are correctly served from my S3 bucket through the CDN (CloudFront), so that’s great!
However, I’m still facing an issue with the precompiled assets
The precompiled assets are still not being served correctly from the CDN
When I set the DISCOURSE_CDN_URL to the CloudFront URL (i.e., https://dsuqioxhrz2qn.cloudfront.net), the precompiled assets URLs become:
• https://dsuqioxhrz2qn.cloudfront.net/stylesheets/color_definitions_shades-of-blue_7_1_e6f11758f9c015d1e5ed9b08c437e9c5c267c932.css?__ws=forum.hobiguru.com
• https://dsuqioxhrz2qn.cloudfront.net/stylesheets/discourse-presence_308d905aa5c03567866fec50e9a28d8721ab0463.css
The problem is that these paths don’t exist in my S3 bucket. The precompiled assets are uploaded under /assets/*
folder in S3 (e.g., /assets/locales, /assets/plugins, /assets/scripts), but there’s no /stylesheets/
folder and of course loading of those URLs are resulting in 403 forbidden.
If, however I change the DISCOURSE_CDN_URL: https://forum.hobiguru.com
then my forum is working correctly, but the assets are now served from the server (e.g. https://forum.hobiguru.com/) and not from the CDN (e.g. https://forum.hobiguru.com/stylesheets/admin_308d905aa5c03567866fec50e9a28d8721ab0463.css?__ws=forum.hobiguru.com
)
My current setup (for context) is:
app.yaml
DISCOURSE_USE_S3: true
DISCOURSE_S3_REGION: eu-central-1
DISCOURSE_S3_ACCESS_KEY_ID: AKIA......LQMB
DISCOURSE_S3_SECRET_ACCESS_KEY: PaXQu7pKN.....fJNY
DISCOURSE_S3_CDN_URL: https://dsuqioxhrz2qn.cloudfront.net # Ensure CDN URL points to CloudFront
DISCOURSE_CDN_URL: https://forum.hobigur.com # NOTICE THIS!
DISCOURSE_S3_BUCKET: hobiguru-s3-bucket-eu
and the precompile hooks:
hooks:
after_assets_precompile:
- exec:
cd: $home
cmd:
- sudo -E -u discourse bundle exec rake s3:upload_assets
- sudo -E -u discourse bundle exec rake s3:expire_missing_assets
It seems that after precomiling the assets there get uploaded to S3 into a certain structure, but then when loaded throught the CDN the path to the objects are a bit off