DNS records
To start routing client traffic through your CDN, set up a custom domain. If you useCNAME records for your custom domain, these records can’t point to apex domains.
But most CDN providers offer workarounds.
For example, Fastly offers Anycast options
and Cloudflare offers CNAME flattening.
Host header forwarding
When an HTTP request is made to a website, the client adds aHost header to the request.
The value of this header is the domain name the request is made to.
When a server hosts multiple websites, like what a CDN does,
it can use the Host header to identify which domain to access to handle the request.
When a request is made from a client to fetch a resource on a CDN edge server,
the Host header value is rewritten to point to the CDN.
If the requested resource isn’t cached on the edge server,
the edge server makes a request to the Upsun server to pull and cache the resource.
For this process to be successful,
set an X-Forwarded-Host header to forward the original Host header value to the Upsun server.
Use your root domain as the value of your X-Forwarded-Host header,
for example: example.com.
To ensure your app handles the X-Forwarded-Host header,
you might need to adjust your app configuration.
For more information on how to set up an X-Forwarded-Host HTTP header,
see your CDN provider’s official documentation.
Disable the router cache
When you use a CDN, the Upsun router HTTP caching becomes redundant. To disable it, change your cache configuration for the routes behind a CDN to the following:.upsun/config.yaml
Prevent direct access to your server
When you use a CDN, you might want to prevent direct access to your Upsun server for security purposes.IP filtering and HTTP auth
While using password or IP based authentication might be possible, it is insecure, and unreliable. There are many scenarios in which the implementation can fail, and the security features circumvented. Furthermore, IP based filtering will usually be impossible due to the fact that most CDNs use thex-forwarded HTTP header, which your project origin will use as the visitor IP address.
Both methods are highly insecure, and we highly recommend against them.
Enable mTLS
If your CDN provider supports it, you can secure your site through mTLS. To enable mTLS, follow these steps:- Obtain an Origin Certificate Authority (CA) certificate from your CDN provider.
-
Check that the CA certificate is a
.crtfile. If the file is a.pemfile, rename it tocdn.crt. -
Add the
cdn.crtfile to your Git repository. -
Change your routing configuration for the routes behind a CDN to the following:
.upsun/config.yaml