Setting up AWS CloudFront with Blossom
Learn how to set up AWS CloudFront as a CDN in front of your Blossom application
This guide walks you through setting up AWS CloudFront as a Content Delivery Network (CDN) in front of your Blossom application.
Prerequisites
- A Blossom application
- A domain (e.g.,
mysite.com) - AWS CloudFront distribution
Configuration Steps
1. DNS Configuration
-
Create a CNAME record for your domain pointing to your CloudFront distribution:
mysite.com -> d34jqxq7ceb9eo.cloudfront.net (CNAME) -
Create a subdomain for the Blossom origin:
origin.mysite.com -> [Origin target shown by Blossom]
2. CloudFront Configuration
- Create a CloudFront distribution with the following settings:
- Origin domain:
origin.mysite.com - Origin protocol: HTTP only
- Viewer Protocol Policy: “Redirect HTTP to HTTPS”
- Origin domain:
4. Blossom Domains
Configure two domains in your Blossom application:
mysite.com(HTTP Only)origin.mysite.com(HTTP Only)
Important Notes
- CloudFront communicates with the configured Blossom origin using HTTP
- End users access the site via HTTPS
- CloudFront automatically redirects HTTP to HTTPS for end users
- Self-signed Blossom origin certificates are not supported by CloudFront
- For HTTPS between CloudFront and the origin, use a Blossom Domain with a publicly trusted certificate
Rails CDN SSL Configuration
When a CDN terminates HTTPS before forwarding a request to Rails, tell Rails whether the origin connection is HTTP or HTTPS.
- If the Blossom Domain uses HTTP Only, set
CDN_TERMINATES_SSL=true. - If the CDN uses HTTPS to reach the Blossom origin, leave the variable unset.
Keep force_ssl enabled in both cases:
config/environments/production.rb
# Set this only when the CDN accepts HTTPS and sends HTTP to Blossom.
config.assume_ssl = ENV["CDN_TERMINATES_SSL"] == "true"
config.force_ssl = true
assume_ssl makes Rails treat the forwarded request as HTTPS, preventing a
redirect loop while preserving secure URL and cookie behavior. Configure the
CDN to redirect public HTTP requests to HTTPS.
See the Rails configuration reference for
config.assume_ssl
and config.force_ssl.
Debugging Tips
- To test your setup, use: curl -svo /dev/null -H “Host: mysite.com” http://origin.mysite.com
- Always include the
Hostheader in your requests as CloudFront does - If experiencing stale content, invalidate the CloudFront cache
Troubleshooting
- TLS Handshake Error: This typically occurs when using a self-signed origin certificate. Use a publicly trusted certificate or HTTP between CloudFront and the origin.
- Stale Content: Use CloudFront cache invalidation to force content refresh.
- Connection Issues: Verify DNS records and the Environment’s health and origin status.