Aside

Creating a static site backup of my Bearblog + self-hosting it on OpenBSD

mgx created a new tool, nanuq: from bear blog to json, markdown, or a static site, and of course, I had to try it. I've been interested in mirroring my Bearblog since he first mentioned doing so in mirrored my bear blog with cloudflare workers.

With nanuq, I was able to export a backup of my posts as a static site in seconds. My blog is back on the bearblog.dev domain now, while my backup lives at squ.eeeee.lol. I did a basic export just to see how it all looks — so it's all barebones right now. I'll play with the CSS more later to pretty things up.

In the process, I learned how to set up a second website at a subdomain on my OpenBSD server and rewrite URLs with httpd.

What I did

Every step that has only text styled like this means that I typed/pasted it into PowerShell and pressed enter afterwards. When I use mg to edit a file, I save & exit by pressing ctrl + x, then ctrl + c (to exit), then y to save changes.

Export Bearblog posts and create a static site

  1. Go to Bearblog dashboard
    1. Go to Settings
    2. Select Export all blog data (bottom link)
    3. A post_export.csv will download
  2. Go to nanuq
    1. Scroll down to static site configuration
    2. Fill in the config details:
      1. Site Title
      2. Site Domain
      3. Favicon
      4. Lang
      5. Site Meta Image
      6. Footer text
      7. Inject JS to <head> — I added my CSS stylesheet here: <link href="path/to/styles.css" type="text/css" rel="stylesheet">
      8. Apply CSS — check the box and toss in: html { color-scheme: light dark; } (leaving empty will apply default Bearblog styles)
    3. Select Browse and attach post_export.csv from earlier
    4. Select Export Static Site
    5. A static_site.zip will download
  3. Extract the zip file & see all the .html files within
  4. Open index.html in Firefox to browse the full post archive

Upload static site to server

  1. Log into my server with WinSCP
  2. Go to var > www > htdocs
  3. Create a new directory: squee
  4. Upload my HTML files into the new directory
  5. Visit https://eeeee.lol/squee and confirm it all works

Set up subdomain + security certificate

  1. Set up squ.eeeee.lol subdomain
    • doas mg /etc/relayd.conf
      • Add pass request quick header "Host" value "squ.eeeee.lol" forward to <httpd> to the existing list
  2. Set up security certificate for squ.eeeee.lol subdomain
    • doas mg /etc/acme-client.conf
      • Add squ.eeeee.lol to the existing list
  3. Update and apply new security certificate
    • doas su
    • domain=yourdomain.com
    • acme-client -v $domain
    • rcctl restart relayd
    • exit

Point subdomain to directory

  1. doas mg /etc/httpd.conf
    • Append to the bottom:
server "squ.eeeee.lol" {
  listen on 127.0.0.1 port 8080
  default type text/html
  root "/htdocs/squee"
}
  1. doas rcctl restart httpd
  2. Visit https://squ.eeeee.lol and confirm it all works

Rewrite & redirect rules in httpd

So that going to /something.html, /something/, and /something all display the same page. Regular expressions, I can't. ಠ_ಠ

  1. doas mg /etc/httpd.conf
    • Add a few more lines to what we appended earlier:
server "squ.eeeee.lol" {
  listen on 127.0.0.1 port 8080
  default type text/html
  root "/htdocs/squee"

  location match "^/([^.]+)/$" {
    request rewrite "/%1.html"
  }
  location match "^/([^.]+)$" {
    request rewrite "/%1.html"
  }
}
  1. doas rcctl restart httpd
  2. Visit https://squ.eeeee.lol and confirm it all works

So that going to eeeee.lol/squee redirects to squ.eeeee.lol.

  1. doas mg /etc/httpd.conf
    • Find server "eeeee.lol" and add the redirect after the /pub/ line:
server "eeeee.lol" {
  listen on 127.0.0.1 port 8080
  default type text/html
  location "/pub/*" {
    directory auto index
  }
  location "/squee/" {
    block return 301 "https://squ.eeeee.lol"
  }
}
  1. doas rcctl restart httpd
  2. Visit https://eeeee.lol/squee to confirm that it redirects

References