Setting up this blog

Jan 9, 2019 12:02 · 354 words · 2 minute read tech

This blog is generated by hugo, a static site generator. My flow is to write it markdown files on my laptop, commit it to a git repository and push it to the machine that’s hosting the blog you’re reading. Once the push is successful, a post-commit hook runs hugo and generates HTML pages. Nginx serves these pages.

Next, the firewall needs to be configured and optionally, SSL certificates can be provisioned using Let’s Encrypt. It’s so much better with the pretty green lock icon.

The performance of this site is great because nginx does a great job at serving files. Maintenance is hassle free because git and nginx are stable and all traffic being served is static.

The downtime I experienced is when I botched an OS upgrade that wasn’t necessary in the first place.

  1. Create/update DNS records for your domain
  2. Install hugo on prod.
    • root@prod $ wget the latest release from here, Linux x64
    • root@prod $ tar -xvzf hugo.tar
    • root@prod $ mv hugo /usr/bin
  3. Set up git server
    • root@prod $ mkdir blog.git
    • root@prod $ cd blog.git && git init --bare
    • krishnasr@mbp $ git clone [email protected]:nindalf/blog.git
    • krishnasr@mbp $ cd blog
    • krishnasr@mbp $ git remote add vps [email protected]:blog.git
    • krishnasr@mbp $ git remote add all [email protected]:nindalf/blog.git
    • krishnasr@mbp $ git remote set-url --add --push all [email protected]:blog.git
    • krishnasr@mbp $ git remote set-url --add --push all [email protected]:nindalf/blog.git
    • krishnasr@mbp $ git push all
  4. Pull Git on server
    • root@prod $ git clone /root/blog.git/
  5. Set up post receive hook
    • root@prod $ cd /root/blog.git/hooks
    • root@prod $ vim post-receive and paste in the contents from here
    • root@prod $ bash post-receive - test that it’s working correctly and generating the right output in the right folder
  6. Set up ufw.
    • ufw default deny incoming
    • ufw default allow outgoing
    • ufw allow ssh
    • ufw allow 'Nginx Full'
    • ufw enable
    • ufw status
    • Check result is identical to this
  7. Set up nginx.
    • apt-get install nginx
    • vim /etc/nginx/sites-available/default
    • server_name blog.nindalf.com nindalf.com www.nindalf.com
  8. Set up certificates
    • add-apt-repository ppa:certbot/certbot
    • apt-get update
    • apt-get install python-certbot-nginx
    • certbot --nginx -d blog.nindalf.com -d nindalf.com -d www.nindalf.com
    • Follow interactive tutorial

More context

Shoutout to the great tutorials on DigitalOcean!