An opinionated provisioning script that turns a fresh Ubuntu server into a production-ready Bun host.
- Installs Bun, Nginx, UFW, Certbot (via snap;
SKIP_CERTBOT=1to bring your own ACME client), and sets up a Bun app under/srv/app. - Creates a systemd service
bun-appfor running the Bun app as an unprivilegedbun-appuser inside a systemd sandboxing profile (see Security). - Installs a pinned Bun release system-wide at
/usr/local/bin/bun, after checking its SHA-256 sum (BUN_VERSIONpicks another; see Bun version). - Configures Nginx as a reverse proxy to
localhost:3000and serves static files from/var/www/app/dist(or/var/www/htmlif sample app is skipped). The sample app binds127.0.0.1only, so Bun is reachable just through Nginx. - Configures UFW: limits SSH on every port
sshd -Treports (22 if sshd is absent), allows HTTP (80) and HTTPS (443) via the 'Nginx Full' profile when available. It never resets UFW: existing rules are kept, and the default policy (deny incoming, allow outgoing) is set only while UFW is inactive. If you disable UFW after an install, re-runs leave it disabled (SKIP_UFW=1leaves UFW untouched altogether). - Upgrades every installed package with
apt-get upgradeon each run, re-runs included (FULL_UPGRADE=1forfull-upgrade,SKIP_UPGRADE=1for none), and prints a reboot hint when one is required. A failedapt-get updateis retried up to three times, 10 seconds apart; a running apt or dpkg is waited for first (see Prerequisites). - Installs a Cloudflare IP updater with a daily systemd timer, so Nginx logs
the real client IP behind Cloudflare and can optionally refuse requests
that bypass it (set
SKIP_CLOUDFLARE=1to skip; see Cloudflare). - Optionally creates a sample Bun app at
/srv/appand enables the bun-app service (setSKIP_BUN_APP=1to skip; Ubuntu's stock Nginx site is then kept). - Safe to re-run: files you may have edited are kept (see Re-running the installer). A second run started while one is in progress exits 1 and changes nothing.
- Intended for provisioning Ubuntu servers (22.04+); run as root/sudo with internet access.
| Software | Source | License |
|---|---|---|
| Bun | GitHub release zip, pinned (1.4.4), SHA-256 verified | MIT |
| Nginx | Ubuntu apt (22.04, 24.04) | BSD-2-Clause |
| Certbot | Snap, latest release | Apache 2.0 |
Certbot is the snap only, as its docs recommend; there is no apt
fallback. snapd is installed through apt when missing. With
SKIP_CERTBOT=1, neither is installed.
The installer sets up one host for one Bun app. It does not cover:
- Several apps per host, containers, or config management. Ansible, Terraform and similar tools can run the installer, but it ships no integration for them. To run your own app in a container behind its Nginx, see Run your app in a container.
- Host hardening. SSH hardening, fail2ban and CIS benchmarks belong to your host's baseline image.
- Logging and metrics agents. The data lives in the systemd journal (
journalctl -u bun-app), the Nginx logs under/var/log/nginx/, and the app state in/var/lib/bun-app; pick your own agent to ship it.
What the installer does promise, and for how long: docs/compatibility.md.
Pipe the latest release's installer to bash (runs as root with sudo):
Important
Piping remote scripts to a shell executes code from the network — review the script before running.
curl -fsSL https://github.com/acfatah/ubuntu-bun-server-setup/releases/latest/download/install.sh | sudo bashA release installer fetches the templates of its own tag and checks each one against the SHA-256 sums built into it; a mismatch stops the install before the file is written.
Note
Release installers exist from 0.5.0 on. Older releases have no
install.sh asset, so their versioned URLs return 404.
Versioning. Releases follow SemVer from 1.0.0. The release notes on GitHub Releases are the changelog. What stays stable, what each bump means and how long a release is supported: docs/compatibility.md.
Other ways to install (skipping the sample app, from a clone, a pinned and checked version, the development channel, another Bun version): docs/installation.md. Prerequisites, such as Ubuntu 22.04+ and a usable snapd, are listed there too.
When done:
- Check Bun:
bun --version - Bun app service:
systemctl status bun-app(logs:journalctl -u bun-app -f) - App data (DB, uploads):
/var/lib/bun-app, also reachable as/srv/app/data. - Sandbox score:
systemd-analyze security bun-app. - Nginx default site:
http://<server-ip>serving/var/www/app/dist(/var/www/htmlwithSKIP_BUN_APP=1). - Get HTTPS cert for your Nginx site:
certbot --nginx. - Installer log:
/var/log/bun-installer.log(every run is appended).
If a step fails, the installer stops, exits non-zero and prints
install failed at line N (<step>). If it completes but something is not
running (Certbot unless skipped, Nginx, bun-app, the /healthz probe),
the summary lists it and the exit status is non-zero.
Operator documentation lives in docs/:
- Installation: prerequisites, install options, pinned and development channels, template source, Bun version, air-gapped and proxied installs.
- Configuration: a reference table of every setting and flag, then the environment toggles in detail.
- Architecture: the install flow step by step, what runs, the Nginx files, and what a re-run keeps or rewrites.
- Operations: health check, logs, re-running the installer, upgrading from older releases, TLS with Certbot, upgrading Bun, restarts, backups.
- Your app: what the host expects from an app, extending or replacing the sample, frontend plus API, deploying with rollback.
- Cookbook: setups beyond the stock app, each with a tested example, such as running your app in a container.
- Cloudflare: real client IP, "Cloudflare only", the IP list updater, removing it.
- Security: threat model, service user, environment file, filesystem layout, what the web root serves, systemd sandbox and limits, troubleshooting.
- Troubleshooting: install failures, apt and
snapd, the SSH rate limit,
--checkproblems, client IPs, Cloudflare fetches. - Upgrading and support: moving a host to a newer release, the support window, known gaps.
- Compatibility: the 1.x stability promise and support window.
Contributors: CONTRIBUTING.md covers the test suites.
The sample app answers GET /healthz with ok, and install.sh --check
re-runs the summary's checks at any time, without root (exit 0 when
healthy, 1 on any problem). Endpoint, --check, shipping logs and the
installer log: docs/operations.md.
Re-running is safe: it upgrades packages, brings Bun to the pinned
version, and keeps every file you may have edited (Kept existing <path>). The list of kept files, and the notes for Upgrading from 0.3.x
and Upgrading from 0.4.x:
docs/operations.md
(0.3.x,
0.4.x).
Installed by default (SKIP_CLOUDFLARE=1 leaves it out): Nginx logs the
real client IP behind Cloudflare, a daily timer keeps Cloudflare's IP
ranges current, and an optional include answers 403 to requests that
bypass Cloudflare. Setup, updates and removal:
docs/cloudflare.md.
To report a vulnerability, see SECURITY.md; please do not open a public issue.
The app runs as the unprivileged bun-app user in a systemd sandbox,
with its code read-only and its state in /var/lib/bun-app. Service
user, environment file, filesystem layout, sandbox and limits:
docs/security.md.
