Skip to content

About

Bootstrap an opinionated, production-ready Bun application environment on Ubuntu.

Resources

Contributing

Security policy

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

Ubuntu Bun.js TypeScript

Ubuntu Bun Server Setup

GitHub GitHub Release GitHub last commit (by committer)

Sponsored by

Grand Wizard Tech

Introduction

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=1 to bring your own ACME client), and sets up a Bun app under /srv/app.
  • Creates a systemd service bun-app for running the Bun app as an unprivileged bun-app user 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_VERSION picks another; see Bun version).
  • Configures Nginx as a reverse proxy to localhost:3000 and serves static files from /var/www/app/dist (or /var/www/html if sample app is skipped). The sample app binds 127.0.0.1 only, so Bun is reachable just through Nginx.
  • Configures UFW: limits SSH on every port sshd -T reports (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=1 leaves UFW untouched altogether).
  • Upgrades every installed package with apt-get upgrade on each run, re-runs included (FULL_UPGRADE=1 for full-upgrade, SKIP_UPGRADE=1 for none), and prints a reboot hint when one is required. A failed apt-get update is 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=1 to skip; see Cloudflare).
  • Optionally creates a sample Bun app at /srv/app and enables the bun-app service (set SKIP_BUN_APP=1 to 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 Included

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.

Out of scope

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.

Quick Start

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 bash

A 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/html with SKIP_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.

Documentation

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, --check problems, 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.

Health check

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 the installer

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).

Cloudflare

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.

Security

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.

About

Bootstrap an opinionated, production-ready Bun application environment on Ubuntu.

Resources

Contributing

Security policy

Stars

3 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages