Setting up a blog


I finally got around to setting up an actual blog to collect thoughts and experiments to then share with friends. And as most of my friends know, I like to share knowledge and I also like to encourage my friends to grow.

I figured I might as well also create a blog post on how I setup this particular blog.

Markdown

I really wanted to have my content primarily be markdown files, so that if I ever want to migrate to some other static site generator tool that it should be rather trivial. There are a ton out there, but I landed on Astro because the docs for getting started were very straightforward and I just didn’t want to have to mess around very much with it at first. I just wanted to create some markdown files and have them look halfway decent.

https://docs.astro.build/en/install-and-setup/#install-from-the-cli-wizard

Short version is it tells you to use the following command to scaffold the project:

npm create astro@latest

It’ll ask to “install” astro, but it’s just going to download the code temporarily in order to bootstrap the project; it doesn’t actually globally install on your system.

Choose where to save it (either current directory with a ”.” or give name of new directory for it to create).

And then I chose “Use blog template”.

Install your dependencies (I chose “no” in the prompt because I wanted to use pnpm instead of npm to install everything but it doesn’t matter, you do you). I also initialized git so that I could back up my project to github (or eventually in self-hosted git server).

Then it’s as simple as npm run dev to start.

I removed most of the footer, and all of the header. And then I added a redirect from the “home page” to just go straight to the blog because I wanted to get right to the content and not have to write up some bogus “welcome” page content or an “about me” page. To do the redirect just add this to your astro config

  redirects: {
    "/": "/blog"
  }

Then I built the blog using npm run build.

Deploying

Self-host

I could have used something like Netlify which would make it pretty easy (just create a free netlify account). If you push your git repo to Github, then you can have Netlify just watch that repo and it’ll re-build and re-deploy the blog every time you push to main.

But I like to self-host so I chose to create a new Linux container (LXC) on my proxmox cluster and then installed nginx on that server.

sudo apt install nginx

I setup ssh access and added an alias for it in my ssh config file.

Host blog-server
  HostName X.X.X.X
  IdentityFile ~/.ssh/your_ssh_private_key
  User ubuntu

Replace the X.X.X.X with the IP address of your server if you go this route. And obviously update the IdentityFile with the path to your ssh key that’s setup on the blog server.

Then I created a deploy.sh file in my project that has one bash line in it.

npm run build && rsync -a dist/ blog:/var/www/html/

Cloudflare

So now it deploys in my local network but I still need to get it wired up to make it publicly available. I use Cloudflare tunnels for this.

I already have a tunnel setup so all I needed to do was go add a public hostname record and point it at my new server and I’m done.

Thoughts

It’s very easy to get going with a basic blog, you just gotta sit down and do it. I think it’s worth doing because even if not many people read it, it’s a good idea to write down what you’re learning. It helps you learn it even better than you otherwise would, and it also serves as personal documentation that you can reference in the future personally. And if someone asks you about something you’ve already written about then you can just share the link. Maybe in another blog post I’ll go over setting up proxmox for a homelab, and maybe a post for setting up a Cloudflare tunnel, but going to skip over those details for now.