2263 words
11 minutes

Self-Hosting an Astro Blog: Pitfalls with R2 Image Hosting, D1, Caddy, and SEO

Self-Hosting an Astro Blog: Pitfalls with R2 Image Hosting, D1, Caddy, and SEO

This blog, codqor.com, went live at the end of October 2026. It isn't on a hosting platform like Vercel or Cloudflare Pages — it's a stack I put together myself: Astro generates the static pages, my own server serves the pages and the admin backend, and the data and images live on Cloudflare. I spent over half a month tweaking it back and forth, and I wrote most of the code together with an AI coding assistant. I didn't miss a single pitfall either. This post records them in the order they actually happened; it's for anyone who wants to self-host a blog while squeezing as much as possible out of free tiers.

1. Overall Architecture: Why I Ended Up Going Purely Static

Part What's used Notes
Frontend Astro 7 + Firefly theme Entire site output as static files
Posts, comments, settings Cloudflare D1 Read and written directly by the admin backend
Images, videos Cloudflare R2 Accessed via a separate subdomain
Pages and admin backend My own server + Caddy Admin sits behind an extra layer of login verification
Build A remote build machine Only receives a content snapshot, holds no keys at all

The publishing flow: I click "Publish site" in the admin panel, the server exports a D1 snapshot and hands it to the build machine; once the build succeeds, the result is fetched back and swapped into production; if it fails, the previous version stays live. One publish takes about 25 to 55 seconds.

Along the way I actually had two changes of heart: once I wanted to switch to SSR so publishing a post wouldn't require rebuilding the whole site, and once I wanted to move D1 and R2 entirely back to my own server. I checked at the time: D1 held only about 1MB, and the 21 images in R2 came to roughly 20MB — moving them was doable. But once the images leave R2 they lose the CDN, and the Workers for comments and stats would have to be rewritten, while the D1 free tier gives 5 million row reads, 100,000 row writes, and 5GB of storage per day (D1 pricing), which a personal blog is nowhere near exhausting. So I decided: stay static, keep D1 and R2 on Cloudflare, and if stats writes ever really hit the free limit, move only the stats.

2. R2 as an Image Host: Cheap, but You Manage Backups and Referer Yourself

R2's free tier is 10 GB of storage per month, 1 million Class A operations, and 10 million Class B operations, and egress traffic is free (R2 pricing). For a blog image host that's basically free.

Two pitfalls I hit:

  1. Images uploaded through the admin panel exist only in R2 — there's no local copy on the server, and D1 only records the file metadata. D1 has Time Travel built in, but the images in R2 have to be backed up regularly on your own.
  2. External videos and cover images wouldn't display. The article tool had a Douyin video embedded, and the page came up black. The cause: Douyin's CDN rejects requests carrying a Referer from another site. In the end I added referrerpolicy=no-referrer for images and filled in <meta name=referrer content=no-referrer> on the page before the result renders.

3. Storing Posts and View Counts in D1

I built the view counter myself: when a page loads, it sends a request to a stats Worker, which writes into the pageviews table in D1; later I added a post_views table that aggregates per post, backfilled 259 rows from historical data, cached the frontend number for 60 seconds, and both the post pages and the list cards now show "N views".

Why not just read the server logs? Because access logging isn't enabled for this site in Caddy, so D1 is the only source of data. Over the first few days after launch (October 30 to November 2), the numbers were 141 visitors and 518 views; of the 57 visitors who came from search, almost all came from Bing — Google sent exactly 1.

IV. Caddy: Configuration Changes Not Taking Effect

Caddy runs in Docker, and the Caddyfile is mounted as a single file into the container. After I used cp to overwrite it and sed -i to modify it, then ran reload, the configuration still didn't take effect. The reason is that both methods generate a new file and replace the inode, while the container is still mounting the old file.

The solution is to write in place, then validate and reload:

Rewrite Caddyfile in place
python3 -c "s=open('Caddyfile.new').read();f=open('/path/to/Caddyfile','r+');f.write(s);f.truncate()"
docker exec caddy caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile
docker exec caddy caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile

If the inode has already changed, the only option is docker restart caddy. The English 404 page and the IndexNow key file were also later configured directly in Caddy, without depending on build artifacts.

The build machine has pitfalls too. It automatically sleeps when idle, and after too much online time it gets cooled down by the platform. On the evening of November 7, publishing failed outright. The backend log said "build machine unreachable, not published." After SSHing in, what I saw was:

Terminal window
machine is cooling down until Sat 2026-11-07 9:56 PM CST

It was cooled down again on November 12. This time the investigation found that the backend was polling video tasks every 10 seconds, making 33,015 connections over several days, so the build machine never had a chance to sleep. I changed it to "poll only when the video feature is in use, and stop when there are no tasks," and the tunnel to the build machine was also changed to disconnect immediately after use.

V. Comments and Turnstile

Comments don't use a third-party service; instead, they use a Worker plus D1. All visitor messages first go into pending moderation; the same IP is limited to 1 per minute and 10 per day, and only a keyed digest of the IP is stored. The online tools in articles and the comment section were later both connected to Cloudflare Turnstile human verification.

I got stuck at the first step when integrating Turnstile: the Cloudflare API token I was using did not have Turnstile edit permission, so I couldn't create a widget. I had to first add "Account → Turnstile → Edit" to the token. After creating it, I restricted the widget to the single domain codqor.com.

A Turnstile token is valid for 300 seconds, can be used only once, and must be verified server-side by calling Siteverify. Just putting a verification box on the frontend won't stop people (official documentation). I tested this on the tool API: after enabling it, requests without a token returned "Please complete human verification first," and requests with a fake token returned "Human verification failed." There's another small pitfall: the Playwright headless browser used for automated testing can't pass Turnstile's interaction, so the end-to-end test was ultimately submitted using a real browser.

VI. SEO: sitemap, noindex, and hreflang

I did an audit on November 7, and there were quite a few problems:

  • Pages such as /dynamic/, /rss/, and /atom/ were mixed into the sitemap, and 11 of the 21 URLs had no lastmod;
  • The About, Privacy, and Contact pages had more than one h1.

The fix was to exclude these paths in filter of @astrojs/sitemap (the official documentation states that if the filter returns false, the page is not included; see this), use the latest article's time as the lastmod for list pages, add noindex, follow to the /dynamic/, /rss/, and /atom/ pages, and change the three page templates to output only one h1.

astro.config.mjs (excerpt, trimmed)
sitemap({
filter: (page) => {
const raw = new URL(page).pathname;
// English page: anything without a translation is not accepted
if (raw.startsWith("/en/") && !isTranslated(raw.slice(3))) return false;
const pathname = raw.replace(/^\/en(?=\/)/, "");
if (["/search/", "/404/", "/dynamic/", "/rss/", "/atom/"].includes(pathname)) return false;
return true;
},
})

Later, Search Console sent an email: "Excluded by noindex tag," with 13 pages excluded. Six of them were intentionally excluded by me, and the other seven were the English homepage and list pages—noindex was added uniformly at the first step of launching the English version, and I forgot to remove it later. This kind of thing can only be discovered by regularly checking the webmaster tools reports.

VII. Bing Reports "Title too long"

Almost all the earliest traffic came from Bing, so I cared a lot when Bing Webmaster Tools reported "title too long." Bing's site scan grades issues as errors, warnings, and notices (Bing Help), but the official help page doesn't state a specific character count; the common claim is that a notice is triggered when the entire <title> exceeds 70 characters.

The pitfall is that the theme automatically appends " - Liam's Blog" to every page title, which takes up 11 characters. The original title of the Xiaomi router article plus the suffix was 74 characters, over the limit. The first time, I cut both articles too aggressively, and even with the suffix they were only thirty or forty characters, losing all the keywords. In the end, I changed it to "Xiaomi AX3000T OpenWrt Guide: HomeProxy Traffic Routing and WireGuard Remote Management," which is 63 characters with the suffix. When calculating title length, include the suffix; just leave some margin—there's no need to cut it to the shortest possible.

8. One-time Submission Interface

I didn't want any automation tool to directly connect to the server and database to modify articles, so I built a one-time submission link in the admin panel:

  • It can only create new drafts, not publish them, nor modify existing articles;
  • It has an expiration time, and the credential becomes invalid immediately after a successful save;
  • When the result is unclear, retrying with the same content within 10 minutes returns the original receipt, so no duplicate drafts are created;
  • External images in the body are automatically transferred to the site's media library, with a maximum of 8 MiB per image and a maximum of 30 links per submission.

The cost is that old articles can't be updated through it—I can only paste and replace them myself in the admin panel. But I think this limitation is worth it: the worst case is just one extra draft.

9. English Mirror

The English version lives under /en/, with the body translated by an AI model configured in the admin panel. Translations are stored in a separate table in D1, and are queued for translation when you click "Publish Site". A few decisions:

  • No automatic redirect based on browser language; only a notice banner is shown to English browsers, to avoid the version crawled by search engines jumping around;
  • Until all translations for a page are complete, the English page stays at noindex, with no hreflang and not included in the sitemap; only after translation is done is it opened for indexing and given reciprocal hreflang with the Chinese page. The sitemap grew from 23 URLs to 38, and later to 51 after the English list pages were opened up.

On November 16 I manually reviewed the English version and found 8 instances of untranslated Chinese missed across 5 articles' bodies, which I've now fixed. The overall quality of the AI translation is good, but you can't skip reviewing it entirely.

10. AdSense First Review Rejected: Low-Value Content

On the evening of November 15 I received an email from AdSense: the site was not approved, and the reason given in the dashboard was "low-value content". The corresponding original text in Google's publisher policies is: ads are not allowed on pages with no publisher content or only low-value content (Google Publisher Policies).

Looking back, the problem was obvious: at the time there were 17 articles in total, 5 of which were under 1,000 characters, including a pinned tools page with only 71 characters and a "Hello World" template text with only 99 characters; another 4 were news commentary. No matter how refined the technical architecture is, it's useless if the content can't hold up.

Remediation plan:

  1. First delete the two thinnest articles (already deleted on November 16; both the Chinese and English versions return 404);
  2. Expand the three benefit articles to over 1,500 characters, adding real steps, screenshots, who it's suitable for, and whether it's still valid;
  3. Check the news commentary figures item by item, cite original sources, and state my own judgment;
  4. Add terms of use and a disclaimer, and flesh out the about page;
  5. Write more hands-on articles like this one based on firsthand operation, and apply for review again once there are around 25 articles and no thin content.

I'll update here once the re-review result comes out.

Share Article

If this article helped you, please share it with others!

Self-Hosting an Astro Blog: Pitfalls with R2 Image Hosting, D1, Caddy, and SEO
https://codqor.com/posts/astro-blog-self-hosting-pitfalls/
Author
Liam
Published at
Related PostsSmart
1
My 256MB Router Can’t Run OpenClash, So I Built TinyLane and Open-Sourced It
TechThe Xiaomi AX3000T has only 256 MB of RAM, making OpenClash too much of a strain, so I packaged the sing-box core, a Go daemon, and a mobile panel into a single binary called TinyLane, with my daily readings at about 35 MB for the core and 20–28 MB for the panel. This article explains why I wrote it, what it can do, the memory pitfalls I hit, and how to install it; the project is open-sourced under GPL-3.0.
2
One API for Multiple TTS Providers: OpenAI Standard Parameter Mapping (MOSS Example)
TechWhen creating voiceovers for short videos, I used Edge TTS, Gemini, and MOSS together, each with different parameters. I later added /v1/audio/speech to my AI relay: clients call it using the OpenAI standard format while the gateway maps parameters per provider (for MOSS, just one line: voice→voice_id), and this article covers the parameter comparison table, mapping implementation, usage examples, and pitfalls.
3
Resend Email Sending from 0 to Launch: Domain Verification, Sending Relay, and Bounce Monitoring
TechA complete record of moving server notification emails from QQ Mail SMTP to Resend: choosing a new account and domain, DKIM/SPF/DMARC on Cloudflare, a sending API where only one relay holds the key, the gotchas that quota resets at UTC and receiving also consumes quota, Bark alerts for bounces, and protection against duplicate sends. Together with the previous post on Cloudflare receiving, it covers both sending and receiving.
4
Xiaomi AX3000T Follow-up: OpenClash Primary/Backup Routing, WireGuard Coexistence, and Lag Troubleshooting
TechTwo weeks after flashing OpenWrt on the AX3000T: switching routing from HomeProxy to OpenClash (Meta core) with primary/backup lines, running WireGuard remote management alongside OpenClash, and tracing cross-ocean link lag from 41 KB/s to 7–8 MB/s.
5
Building a WeChat Mini Game with AI in Two Days: From Topic Selection to Submission and the Filing Rejection Pitfalls
TechFor the individually operated, ad-only single-player WeChat Mini Game Eat Up, Big Fat Fish, AI collaboration was used from topic selection through submission: original characters, a web demo, a 30-level official release, account-type pitfalls, privacy guidelines, and correcting the Filing item by item against the official text after it was rejected over the Age Rating Notice.
Random PostsRandom

Comments

Leave a comment

Share your thoughts

Shown after review
Leave the name empty to post as “Anonymous”0 / 3000

Comments

Newest first · 5 at a time

Loading comments…

Profile Image of the Author
Liam
Notes on tech, life, and thoughts.
Categories
Tags
Latest Moments
Site Statistics
Posts
21
Categories
4
Tags
72
Total Words
87,292
Running Days
0 days
Last Activity
0 days ago
Table of Contents