This blog runs on a small Linode: EmDash on Astro and Node, SQLite for content, Docker with gVisor around the app, nginx in front, a Let's Encrypt certificate and CrowdSec watching the logs. This post is the build sheet for the exact server you are reading it on, in the order it was done.
If you only want the short version: one 2 GB Debian 13 server, key-only SSH over Tailscale, a cloud firewall, a read-only container with no capabilities under gVisor, nginx with modern TLS and a handful of headers, CrowdSec blocking at the firewall and challenging bots at nginx, and a nightly SQLite backup.
There is also a follow-up post on updating it to 1.2
The server
A Linode 2 GB (Shared CPU, 1 vCPU) running Debian 13, in whichever region is closest to you. 1 GB is enough to serve EmDash but not to build it: npm and Astro need more than that during the image build, so either start at 2 GB or add swap.
linode-cli linodes create \
--label myblog --region <region> --type g6-standard-1 \
--image linode/debian13 \
--authorized_keys "$(cat ~/.ssh/id_ed25519.pub)" \
--root_pass "$(openssl rand -base64 32)"The root password is random and thrown away. Nothing logs in with a password.
Before anything else, attach a Linode Cloud Firewall with an inbound policy of drop, and accept rules for TCP 80 and 443 from anywhere, and ICMP. Once setup is done, nothing else gets in, port 22 included. SSH is not open to the internet at all: the server is reached over Tailscale SSH, from devices on your own tailnet. During setup, the firewall also lets TCP 22 in from your own address, so you can log in as root and install Tailscale. Once Tailscale SSH works, delete that rule, and port 22 is closed for good. Linode's Lish console works too if you'd rather never open it. With that rule deleted, SSH stays off the internet entirely.
DNS
Two records in the zone, A and AAAA, pointing at the server. Certbot needs them in place before it can issue the certificate.
Base hardening
Log in once as root (from your own address, before Tailscale), create your own user (youruser below), then lock root out:
adduser --disabled-password --comment "" youruser
usermod -aG sudo youruser
install -d -m 700 -o youruser -g youruser /home/youruser/.ssh
cp /root/.ssh/authorized_keys /home/youruser/.ssh/
chown youruser:youruser /home/youruser/.ssh/authorized_keysSSH settings go in a drop-in file rather than the main config, so package upgrades never conflict with them. /etc/ssh/sshd_config.d/10-hardening.conf:
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
AuthenticationMethods publickey
AllowUsers youruser
X11Forwarding no
AllowAgentForwarding no
AllowTcpForwarding no
MaxAuthTries 3
LoginGraceTime 30
ClientAliveInterval 300
ClientAliveCountMax 2Check it with sshd -t, then systemctl reload ssh, and confirm a second session still gets in before you close the first.
Then the rest of the basics:
- Updates:
apt full-upgrade, thenunattended-upgradesfor security updates. Automatic reboots stay off, andneedrestarttells you when one is due. - Swap: a 2 GB swap file with
vm.swappiness=10, as headroom for image builds. - Kernel settings in
/etc/sysctl.d/90-hardening.conf:kernel.kptr_restrict=2,kernel.dmesg_restrict=1,kernel.yama.ptrace_scope=1, reverse path filtering on, ICMP redirects and source routing off, SYN cookies on. - journald capped at 500 MB with
SystemMaxUse=500M. - Hostname and timezone set, with the hostname in
/etc/hostssosudodoes not complain.
Docker and gVisor
Docker comes from Docker's own apt repository, not Debian's. gVisor's runsc comes from gVisor's apt repository. /etc/docker/daemon.json registers the runtime, caps container logs, and makes no-new-privileges the default:
{
"log-driver": "json-file",
"log-opts": { "max-size": "10m", "max-file": "3" },
"live-restore": true,
"no-new-privileges": true,
"runtimes": { "runsc": { "path": "/usr/bin/runsc" } }
}Why gVisor: EmDash runs sandboxed plugins in workerd, and workerd's own README says it is not a hardened sandbox on its own. gVisor gives the whole container its own application kernel, so code inside it never talks to the host kernel directly.
The site
The site is EmDash's blog template, created with Node 24:
npm create emdash@latest blog -- --template blog --platform node --pm npm
cd blog
npm install @emdash-cms/sandbox-workerd workerdThe scaffolder writes an EMDASH_ENCRYPTION_KEY into .env. That key encrypts plugin secrets and is not part of any database backup, so copy it somewhere safe, such as a password manager, and chmod 600 .env.
The look is all in src/styles/theme.css, which overrides the template's design tokens to follow the WordPress theme this site used before: a black top bar, condensed uppercase Oswald headings, Roboto text in a soft grey, and the cyan of the SHA|SAM logo as the one accent. Dark mode keeps the same layout on a near-black background. Code is IBM Plex Mono. The fonts are set in astro.config.mjs. Astro downloads the fonts at build time and serves them from this site, so no page asks Google for anything.
Dates need one change to the template. EmDash stores them in UTC, and the template formats them with toLocaleDateString() and no time zone, so they come out in the server's zone. Anywhere ahead of UTC, a post published in the morning would show the day before. A small helper in src/utils/dates.ts reads the time zone from the site settings in the admin and formats every date with it:
import { getSiteSetting } from "emdash";
export async function siteDateFormatter(
locale: string | undefined,
month: "long" | "short" = "long",
) {
const timeZone = (await getSiteSetting("timezone")) || "UTC";
const options: Intl.DateTimeFormatOptions = { year: "numeric", month, day: "numeric" };
let format: Intl.DateTimeFormat;
try {
format = new Intl.DateTimeFormat(locale ?? "en-AU", { ...options, timeZone });
} catch {
// An unknown zone name throws; show UTC rather than fail the page.
format = new Intl.DateTimeFormat(locale ?? "en-AU", { ...options, timeZone: "UTC" });
}
return (date: Date | null | undefined) => (date ? format.format(date) : null);
}The home page, the post list, the post page and the post cards each replace their own toLocaleDateString() call with await siteDateFormatter(Astro.currentLocale). This is the pattern in EmDash's site settings guide: read the timezone setting and pass it to Intl.DateTimeFormat. Set the time zone under Settings in the admin once the site is running.
The parts of astro.config.mjs that matter for running behind nginx:
export default defineConfig({
site: "https://blog.example.com",
output: "server",
adapter: node({ mode: "standalone" }),
session: {
driver: sessionDrivers.fsLite({ base: "/app/data/sessions" }),
},
security: {
allowedDomains: [
{ hostname: "blog.example.com", protocol: "https" },
{ hostname: "blog.example.com", protocol: "http" },
],
},
integrations: [
react(),
emdash({
siteUrl: process.env.EMDASH_SITE_URL || "https://blog.example.com",
database: sqlite({ url: "file:/app/data/emdash.db" }),
storage: local({
directory: "/app/data/uploads",
baseUrl: "/_emdash/api/media/file",
}),
trustedProxyHeaders: ["x-real-ip"],
sandboxRunner: "@emdash-cms/sandbox-workerd/sandbox",
migrations: { runtime: "check", dev: "auto" },
}),
],
});session moves sign-in sessions onto the data volume. Astro's Node adapter keeps them under node_modules/.astro by default, which is inside the read-only image, and sign-in fails with a server error right after the passkey is accepted. That one was found the hard way on this server.
allowedDomains tells Astro which forwarded host names to trust, and trustedProxyHeaders lets EmDash see the real client address for its sign-in rate limits. That second one is only safe because nginx is the only way in. The EmDash configuration reference covers each option.
siteUrl repeats the public address in the config, because EmDash optimises locally stored images only when it knows the address at build time. migrations.runtime: "check" stops EmDash applying a migration by itself on start-up. A pending migration answers 503 until a deploy step applies it.
The container
Dockerfile, a two-stage build on Debian slim. workerd is linked against glibc, so Alpine will not do:
FROM node:24-bookworm-slim AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
# npm 11 installs workerd's native binary only when allowScripts approves
# it. Without that it leaves the JavaScript launcher, and the plugin sandbox
# fails at run time, so fail the build instead.
RUN [ "$(head -c 2 node_modules/workerd/bin/workerd)" != "#!" ] || { echo "workerd is not the native binary: approve it in allowScripts" >&2; exit 1; }
COPY . .
RUN npm run build && npm prune --omit=dev
FROM node:24-bookworm-slim
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./
# The migration manifest the build wrote; `emdash migrate` reads it.
COPY --from=builder /app/.emdash ./.emdash
RUN mkdir -p /app/data && chown node:node /app/data
USER node
ENV HOST=0.0.0.0 PORT=4321
EXPOSE 4321
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD ["node", "-e", "fetch('http://127.0.0.1:4321/_emdash/api/health').then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))"]
CMD ["node", "./dist/server/entry.mjs"]The final image also copies .emdash, where the build writes the migration manifest that emdash migrate reads, and has a health check against EmDash's health endpoint. The build fails if workerd's native program is missing, which happens when npm has not approved workerd's install script. Updating this blog to EmDash 1.2 covers that trap.
compose.yaml:
services:
emdash:
build: .
image: shasam-blog:latest
restart: unless-stopped
# Only nginx on this host can reach the site.
ports:
- "127.0.0.1:4321:4321"
networks:
- emdash
environment:
EMDASH_SITE_URL: "https://blog.example.com"
EMDASH_ENCRYPTION_KEY: "${EMDASH_ENCRYPTION_KEY:?set it in .env next to this file}"
# Keeps the V8 heap well inside mem_limit under gVisor.
NODE_OPTIONS: "--max-old-space-size=320"
volumes:
- emdash-data:/app/data
- ./resolv.conf:/etc/resolv.conf:ro
read_only: true
tmpfs:
- /tmp:size=64m
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
pids_limit: 512
mem_limit: 768m
runtime: runsc
networks:
emdash: {}
volumes:
emdash-data:What each part does:
- The port is published on the loopback address only, so the app is reachable from nginx on this host and nowhere else.
read_onlywith a small tmpfs on/tmp: the image cannot be changed at runtime, and the only writable places are/tmp(workerd's config and socket) and the data volume.cap_drop: ALLandno-new-privileges: no Linux capabilities, and no way to gain them.pids_limitandmem_limitstop a runaway plugin from taking the server down with it.NODE_OPTIONScaps the V8 heap at 320 MB, well inside the 768 MB container limit, so Node collects garbage before the container hits its ceiling.runtime: runscruns the lot under gVisor.
resolv.conf is there because gVisor cannot reach Docker's internal DNS server on a user-defined network, so every outbound lookup fails without it. Point it at resolvers you trust:
nameserver 1.1.1.1
nameserver 9.9.9.9
options ndots:0Build, check that gVisor and workerd both work, then start it:
docker compose build
docker run --rm --runtime=runsc --entrypoint sh <image> \
-c 'uname -r; ./node_modules/workerd/bin/workerd --version'
docker compose up -d
curl -sI http://127.0.0.1:4321/ | head -1uname -r ends in gvisor when it is working.
nginx and TLS
nginx comes from Debian, which already turns off server_tokens and old TLS versions. Three pieces of configuration:
- A catch-all on port 80 that returns 444 to any host name it does not know, and a catch-all on 443 with
ssl_reject_handshake on, so scanners hitting the bare IP get nothing. - A port 80 server for the blog that answers ACME challenges from
/var/www/letsencryptand redirects everything else to HTTPS. - The HTTPS server, which proxies to the container.
The certificate comes from Certbot in webroot mode, so Certbot never edits the nginx config:
certbot certonly --webroot -w /var/www/letsencrypt -d blog.example.com \
--deploy-hook "systemctl reload nginx"The HTTPS server block:
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name blog.example.com;
ssl_certificate /etc/letsencrypt/live/blog.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.example.com/privkey.pem;
ssl_session_tickets off;
# EmDash sends the first three itself; one copy each, from nginx.
# Server-Timing would show internal timings to every visitor.
proxy_hide_header X-Content-Type-Options;
proxy_hide_header Referrer-Policy;
proxy_hide_header Permissions-Policy;
proxy_hide_header Server-Timing;
add_header Strict-Transport-Security "max-age=63072000" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=()" always;
add_header Content-Security-Policy "frame-ancestors 'self'; base-uri 'self'; object-src 'none'" always;
client_max_body_size 50m;
location / {
proxy_pass http://127.0.0.1:4321;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}The cipher list follows Mozilla's intermediate profile. $connection_upgrade comes from a map on $http_upgrade in conf.d, as in the nginx WebSocket guide. X-Forwarded-For is set to the client address rather than appended to, so nothing a client sends in that header gets passed through.
CrowdSec
CrowdSec reads the nginx logs and the SSH journal, spots brute force and scanning, and bans the source address. Install the engine from CrowdSec's own repository (Debian's package is far behind), then the nftables firewall bouncer, which does the blocking:
curl -s https://install.crowdsec.net | sudo sh
sudo apt install crowdsec crowdsec-firewall-bouncer-nftables
sudo cscli collections listOn install it finds nginx and sshd by itself and enables the matching collections, along with the community blocklist. fail2ban would do the same job twice, so it is not installed.
In front of the site, the nginx bouncer adds CrowdSec's AppSec component: a web application firewall with virtual patching and generic rules, and a JavaScript bot challenge in balanced mode for clients it has not verified. The challenge page answers with HTTP 200, so check pages by what they say, not their status code. The feed, the sitemaps, robots.txt and /_emdash/api/ are exempt from the challenge, and the WAF still inspects them. AppSec's processing timeout is 2000 ms. At the 500 ms default, slow checks timed out and let requests through with no WAF and no challenge.
Test that a ban actually blocks, from a machine outside the server:
sudo cscli decisions add --ip <your address> --duration 4m --reason test
# requests from that address now time out
sudo cscli decisions delete --ip <your address>Note that -r in cscli decisions add means range, not reason. The reason flag is --reason.
Backups
A small script, run nightly by a systemd timer, takes a consistent copy of the database with SQLite's .backup command, checks it with PRAGMA integrity_check, tars the uploads folder, and keeps 14 days in /var/backups/blog. A copy on the same disk only protects against mistakes, not against losing the server, so turn on Linode Backups or copy the files somewhere else as well. And keep the encryption key from .env with them.
First sign-in
With nginx and the certificate in place, open https://blog.example.com/_emdash/admin/ and run the setup wizard. EmDash signs in with passkeys, which are bound to the address you register them on. That is why the wizard waits until the site is on its real HTTPS address.
What this does not cover
workerd on Node enforces wall-time limits for plugins but not CPU or memory limits, which is why the container carries its own mem_limit and pids_limit. gVisor narrows what a compromised plugin could reach, but the best protection is still installing only plugins you trust. Watch EmDash's sandbox documentation for changes there.





No comments yet