Hosting Static sites like Quartz on Cloudflare Pages
Cloudflare workers and pages
Assuming you have your website built and ready to host/deploy in a repo.
- Access your cloudflare account.
- Go to cloudflare workers and start a project by pointing it to your own repo (you should only authorize it for one repo)
- Set your build command. Quartz example below:
- Production branch: v4
- Framework preset: None
- Build command:
npx quartz build
if you want to also grab the timestamps from git usegit fetch --unshallow && npx quartz build
- Build output directory: public
- Save and Delply
With this you have your project up and running on cloudflare pages.
Setting up your custom domain
- Under your project click on: Custom domains -> Set up a custom domain
- type your domain in the box and click: continue -> begin DNS transfer
- type your domain again
- choose the plan tier (can be free)
- after cloudflare pulls your dns records, it will ask you to go to your domain name registrar (the entity you rent your dromain from) to change their "dns server" to the ones they give you
- If you're using namecheap you'll find it under "Domain" NOT "Advanced DNS"
- Find "Nameservers" and click the dropdown list to choose "Custom DNS"
- Add the two dns servers that cloudflare gives you and save it.
- click check nameservers and wait for an email from cloudflare telling you the transfer was complete
- click continue
- click Activate domain
- you can add an A record to your domain with the name www and the value being a random ip address, have that proxied through cloudflare and you're good to go.
- OPTIONAL: If the www doesn't work:
- Go to your dashboard (main page of your account)
- click on Bulk Redirects
- Give your list a name and give a description
- Click "manually add URL redirects"
- type your domain address with a www. preceeding it
- type your domain address without it as the target URL
- click Next -> Next
- It's going to ask you to add a rule for that, name it whatever you want (eg. www to root)
- Choose the domain or project this rule will apply to (in this case choose that worker project hosting your site)
- Click "Save and Deploy"
Enabling DNSSEC
- Once you've setup your domain with cloudflare you can go to your domain settings, on the left side you'll find DNS -> settings
- Click on Enable DNSSEC, and it will give you a list of values to input into your registrar (if you didn't rent your domain from cloudflare)
- In namecheap if you're using that one you can go to your domain
- Advanced DNS tab
- under DNSSEC enable it and add a row, fill the values of that row with the values cloudflare gives you for dnssec.