Skip to main content
Icon

CDN Configuration

Set up your CDN to work seamlessly with your OwnStak environments

Origin Configuration

When setting up your CDN, you need to point it to your environment's backend URLs. These URLs are visible in your environment overview page in the OwnStak Console. You should configure one origin per cloud backend in your environment.

Header Configuration

To ensure proper routing and functionality, your CDN must be configured to send the correct host header. You have two options:

Option 1: Using Host Header

Configure your CDN to send the Host header matching the host from your environment link. If you need to preserve the original host, you can use the X-Forwarded-Host header to pass it through. The OwnStak Proxy by default preserves the received Host in the X-Forwarded-Host header when serving traffic.

Example configuration:

Host: your-environment.backend1.your-org.ownstak.link
X-Forwarded-Host: your-original-domain.com
note

The X-Forwarded-Host header can contain multiple comma-separated values when a request passes through multiple proxies that override the Host header. For example: your-original-domain.com, another-domain.com. Ensure that your application correctly parses and validates the header in this case.

Option 2: Using X-Own-Host Header

Alternatively, you can use the X-Own-Host header to specify the environment host:

X-Own-Host: your-environment.backend1.your-org.ownstak.link

Guides

AWS CloudFront

AWS CloudFront is a global content delivery network that integrates seamlessly with other AWS services. The guide below shows you how to configure it for simple OwnStak setup through the AWS Console. Advanced users can use other configuration options.

Cloudfront

  1. Log into AWS Console
  2. Create Distribution
    • Click Create Distribution
    • Select Single website or app
    • Click Next
  3. Specify Origin Type
    • Origin Type: Select Other
    • Origin Domain: Enter your environment link hostname (e.g., nextjs-prod.backend1.your-org.ownstak.link)
    • Origin Path: Leave empty
    • Origin Settings: Select Customize origin settings
    • Add custom header: Click on Add header → Add Header with name: x-own-host and your environment link hostname as value (e.g., nextjs-prod.backend1.your-org.ownstak.link)
    • Click Next
  4. Security Settings
    • Web Application Firewall (WAF): Configure additional security protections or select Do not enable security protections for now.
    • Click Next
    • Click Create distribution
  5. Configure Alternate Domain Names (CNAMEs)
    • In the SettingsAlternate domain names section click on Add domain
    • Alternate domain names (CNAMEs): Add your domain (e.g., www.your-domain.com)
    • SSL Certificate: Import a certificate for your domain or request new certificate and perform domain validation through the CNAME record.
    • Minimum protocol version: Select at least TLSv1.2
  6. Create DNS Record
    • Go to your domain's DNS provider (Route 53, Cloudflare, Namecheap, etc..)
    • Create a CNAME record:
      • Name: Your sub/domain (e.g., www or @ as root domain)
      • Value: Your Cloudfront distribution domain name (e.g., d1234abcd.cloudfront.net)
      • TTL: 300 seconds (or as preferred)
  7. Done
    • Your site is ready to receive traffic through CloudFront
    • Other environments can be configured with additional distributions or behaviors

Cloudflare

Cloudflare is a popular CDN provider with a generous free tier. The guide below shows you how to configure it for a simple OwnStak setup through the UI. Advanced users can use other configuration options.

Cloudflare

  1. Log into Cloudflare Dashboard
  2. Navigate to DNS settings
    • Go to DNSRecords
    • Click Add record
  3. Create new CNAME Record
    • Type: CNAME
    • Name: Your sub/domain (e.g., www, or @ for root domain)
    • Target: Your environment link hostname (e.g., nextjs-prod.backend1.your-org.ownstak.link)
    • Proxy status: Enable the proxy (orange cloud)
    • TTL: Keep Auto
  4. Save the Record
    • Click Save to create the CNAME record

Cloudflare2

  1. Navigate to Rules settings
    • Go to RulesOverview
    • Click Create ruleRequest Header Transform Rule
  2. Request Header Transform Rule
    • Rule name: Add x-own-host header to request or any other name
    • If incoming requests match: Custom filter expression → Field: Hostname, Operator: Equals, Value: www.your-domain.com
    • Then: Modify request header
  3. Set Header Configuration
    • Operation: Set static
    • Header name: x-own-host
    • Value: Your environment link hostname (e.g., nextjs-prod.backend1.your-org.ownstak.link)
  4. Save the Rule
    • Click Deploy to activate the new rule
  5. Done
    • Your site is ready to receive traffic. Other environments can be configured the same way.

Cache Clearing

After each deployment, you'll need to clear your CDN cache to ensure users receive the latest version of your application.

Each CDN provider has its own method for cache invalidation:

  • AWS CloudFront: Use the AWS Console or CLI to create invalidation requests for specific paths or the entire distribution
  • Cloudflare: Use the Cloudflare dashboard or API to purge cache for specific URLs or the entire zone

For automated cache clearing, integrate the appropriate CDN API calls into your CI deployment pipeline to trigger cache invalidation immediately after successful deployments.

We're actively working on deeper integrations with popular CDN providers to streamline the setup and management process.