https://www.gravatar.com/avatar/7ccf1999fbd849e739bbc3403990689d?s=240&d=mp

Daniel Mason

Site Reliability Engineer, Dad, Pilot

GeoIP blocking countries using Nginx

Quick and easy way to block entire countries using simple nginx rules. Note this is for Ubuntu/Nginx but may work on other systems.

Install required packages & add to nginx config.
The GeoIP DB will be under /usr/shared/GeoIP/GeoIPv6.dat (Or GeoIP.dat for v4 only):

1
2
sudo apt install -y libnginx-mod-http-geoip geoip-database
echo 'geoip_country /usr/share/GeoIP/GeoIPv6.dat;' > /etc/nginx/conf.d/geoip.conf

Add this block under the main “http” block in nginx.conf:

1
2
3
4
5
# /etc/nginx/nginx.conf
map $geoip_country_code $allowed_country {
    default yes;
    BD no; # Country code to block - Can list mulitple
}

Then we need to add a simple check in our site vhost inside the server { block, but before the location / block:

Expanding OpnSense root disk (21.7+)

Expanding root partition on OpnSense VM

  • Expand underlying VM disk
  • Reboot
  • Run below commands to online resize
  • Reboot (Optional?)
1
2
3
4
5
6
7
8
# View the layout
gpart show
# Resolve GPT issue before extending
gpart recover da0
# Make it use all the new space
gpart resize -i 3 da0
# Grow the FS to fill the new partition
growfs /dev/gpt/rootfs

iCloud synced SSH configs on macOS

Maintaining SSH configs can be a pain when you’re hopping between multiple devices, even more when syncing apps (Synology/NextCloud/etc) are blocked on some networks/devices.

Make sure you have iCloud Drive enabled and this will symlink your SSH config + key to a folder in iCloud Drive and sync across devices.

The iCloud Drive is located at ~/Library/Mobile Documents/com~apple~CloudDocs. By putting this file + your config/id_rsa files in here, it will simply symlink them. Warning - the setup script will overwrite existing config/id_rsa files.

Mastodon.nz and the recent twitter influx

Where to begin.. It’s been an interesting fortnight!

I started hosting mastodon.nz around January 2020 on my home ‘server’ for myself and few friends. It started off as a small LXC container inside Proxmox with 2 cores and 2GB RAM allocated. It stayed this way until about 6 months ago when I kept having scheduled power outages and I couldn’t keep running it from my house while maintaining a reasonable uptime.