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
- Go to Bearblog dashboard
- Go to Settings
- Select Export all blog data (bottom link)
- A post_export.csv will download
- Go to nanuq
- Scroll down to static site configuration
- Fill in the config details:
- Site Title
- Site Domain
- Favicon
- Lang
- Site Meta Image
- Footer text
- Inject JS to
<head>
— I added my CSS stylesheet here:<link href="path/to/styles.css" type="text/css" rel="stylesheet">
- Apply CSS — check the box and toss in:
html { color-scheme: light dark; }
(leaving empty will apply default Bearblog styles)
- Select Browse and attach post_export.csv from earlier
- Select Export Static Site
- A static_site.zip will download
- Extract the zip file & see all the .html files within
- Open index.html in Firefox to browse the full post archive
Upload static site to server
- Log into my server with WinSCP
- Go to var > www > htdocs
- Create a new directory:
squee
- Upload my HTML files into the new directory
- Visit https://eeeee.lol/squee and confirm it all works
Set up subdomain + security certificate
- 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
- Add
- Set up security certificate for squ.eeeee.lol subdomain
doas mg /etc/acme-client.conf
- Add
squ.eeeee.lol
to the existing list
- Add
- Update and apply new security certificate
doas su
domain=yourdomain.com
acme-client -v $domain
rcctl restart relayd
exit
Point subdomain to directory
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"
}
doas rcctl restart httpd
- 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. ಠ_ಠ
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"
}
}
doas rcctl restart httpd
- Visit https://squ.eeeee.lol and confirm it all works
So that going to eeeee.lol/squee redirects to squ.eeeee.lol.
doas mg /etc/httpd.conf
- Find
server "eeeee.lol"
and add the redirect after the/pub/
line:
- Find
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"
}
}
doas rcctl restart httpd
- Visit https://eeeee.lol/squee to confirm that it redirects