Couple thoughts on self-host
The idea came to me when I was exploring options to host my Hugo blog, a place for me to ramble.
I needed somewhere to deploy the blog and a domain name that would remain human-readable. Then I started thinking about version control and continuous delivery. I could have put the site on an established platform and called it a day. But isn't that too simple?
I also wanted room for subdomains and other useful software in case I wanted to escape parts of the Google ecosystem. The first piece happened to be Gitea, a lightweight Git service. I have nothing against GitHub, but if I was going for the self-host life, why not host Git too?
More importantly, I knew I would learn a lot by putting the pieces together myself. Indeed I did. I never regretted spending several weeks working on it, although the system looks quite different from my first attempt.
The services
- Blog: Hugo
- Git: Gitea
- Reverse proxy: Nginx
- Database: SQLite, inside Gitea
- Certificates: Certbot and Let's Encrypt
- Mail: Proton Mail
- Cloud: DigitalOcean
- Domain registrar: Name.com
The goals haven't changed much: keep my code in a private Git service, publish the blog with one command, and serve both sites over HTTPS. I just run a lot less to get there.
Why Docker, and why less of it
At first I wondered whether I should install everything directly on the Droplet. Installing Gitea that way would have been simpler in the short term. But removing it later, keeping dependencies compatible, and adding more services would eventually clutter the host.
That led me to Docker Compose. My first sketch put everything in containers:

These days only Gitea runs in a container. Nginx and Certbot come from Ubuntu's packages, so they get security updates along with the rest of the system, and the blog is just a folder of files.
What it looks like now
Internet
|
v
Nginx on ports 80 and 443 (host)
| \
| \ serves static files
v v
Gitea on 127.0.0.1:3000 /srv/minhdb-blog/current
(Docker, SQLite) (a link to the latest release)
Nginx terminates TLS for both domains. It proxies code.minhdb.com to Gitea and serves minhdb.com straight from disk. Gitea only listens on loopback, and Git over SSH is off; I clone and push over HTTPS.
The firewall allows 80 and 443 from anywhere and SSH only from my own address. Logging in takes a key, root login is off, and Ubuntu installs security updates on its own.
Gitea
The whole Compose file is one service now:
services:
gitea:
# Pinned to a reviewed release and its digest, so a restart can't upgrade it.
image: docker.gitea.com/gitea:<version>-rootless@sha256:<digest>
restart: unless-stopped
user: "1000:1000"
read_only: true
tmpfs:
- /tmp
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
volumes:
- /opt/gitea/data:/var/lib/gitea
# Gitea can read its config but not change it.
- /opt/gitea/config:/etc/gitea:ro
ports:
# Only Nginx on the same host can reach it.
- "127.0.0.1:3000:3000"
SQLite replaced MariaDB. I'm the only user, so one database file is plenty, and it's one less service with a password and a port.
The settings I care most about:
[service]
DISABLE_REGISTRATION = true
REQUIRE_SIGNIN_VIEW = true
[openid]
ENABLE_OPENID_SIGNIN = false
ENABLE_OPENID_SIGNUP = false
[security]
INSTALL_LOCK = true
# Only the Docker gateway that Nginx's traffic arrives from, never "*".
REVERSE_PROXY_TRUSTED_PROXIES = 172.30.0.1/32
[actions]
ENABLED = false
My admin account uses two-factor authentication, and the secrets in app.ini were generated fresh on the new server.
Nginx for Gitea
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name code.minhdb.com;
ssl_certificate /etc/letsencrypt/live/code.minhdb.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/code.minhdb.com/privkey.pem;
client_max_body_size 256m;
# Slow down password guessing.
location = /user/login {
limit_req zone=gitea_login burst=5 nodelay;
include /etc/nginx/snippets/gitea-proxy.conf;
}
location / {
include /etc/nginx/snippets/gitea-proxy.conf;
}
}
The proxy snippet sets X-Forwarded-For to the client address instead of appending to whatever the client sent, so nobody can hand Gitea a fake address chain. Requests for hostnames I don't serve get dropped, both on port 80 and during the TLS handshake on 443.
I run sudo nginx -t before every reload. A failed test leaves the old config running, which once made me chase a problem that wasn't in the file I was looking at.
Publishing the blog
There is no CI anymore. I build the site on my own machine with a pinned Hugo version and upload it with one script:
scripts/publish.sh --dry-run # build and check only
scripts/publish.sh # build, upload, switch, verify
The script refuses to run unless main is committed and pushed. It sends the built site as one archive over SSH to a deploy account whose key can run exactly one command on the server. That command checks the archive (no links, no .. paths, a size limit), unpacks it into a new release folder, and points current at it in a single rename. It keeps the last five releases, so rolling back is one command too.
Nothing on the server builds or runs code from the blog repository.
Certificates
Certbot comes from Ubuntu's package, which already installs a renewal timer. I added one line so Nginx reloads after each renewal:
echo 'deploy-hook = systemctl reload nginx' | sudo tee -a /etc/letsencrypt/cli.ini
sudo certbot renew --dry-run
What I verify
sudo docker compose -f /opt/gitea/compose.yaml ps # Gitea is "healthy"
sudo ss -tlnp # 3000 only on 127.0.0.1
sudo nginx -t
curl -sI https://code.minhdb.com | head -1
curl -s https://minhdb.com/.release # the commit I just published
sudo docker exec gitea gitea admin user list # only my account
The last one is new. I used to trust the registration setting; now I look at the user list.
What I learned
Running my own services still teaches me more than anything else I do on the side. The first version taught me how to get containers running. The current one taught me to run fewer things, give each one less access, and check what is actually there instead of what the config says should be there.
Backups that live off the Droplet are next on my list.