OpenUptime

Self-host OpenUptime

Run your own copy on Cloudflare Workers or in Docker. Both use the same code and a Postgres database you control.

Pick one:

  • Docker: one container plus Postgres, on any machine. Quickest to try.
  • Cloudflare Workers: two Workers, a Queue and Hyperdrive in front of Postgres. Runs checks from Cloudflare's network.

Docker

One container runs the API, the web app and the check scheduler. The compose file also starts Postgres.

Requirements

  • Docker with Compose v2
  • A machine that can reach the services you want to monitor

Start it

Option A: published image. Tagged releases are published to ghcr.io/becoolme/openuptime (linux/amd64 and linux/arm64); nothing to clone or build.

mkdir openuptime && cd openuptime
curl -fsSLO https://raw.githubusercontent.com/becoolme/openuptime/main/docker-compose.yml
curl -fsSL https://raw.githubusercontent.com/becoolme/openuptime/main/.env.docker.example -o .env
# edit .env: set POSTGRES_PASSWORD and BETTER_AUTH_SECRET (openssl rand -hex 32),
# and uncomment OPENUPTIME_IMAGE (pin ghcr.io/becoolme/openuptime:0.1.0 or follow :latest)
docker compose pull && docker compose up -d

Option B: build from source.

git clone https://github.com/becoolme/openuptime.git
cd openuptime
cp .env.docker.example .env
# edit .env: set POSTGRES_PASSWORD and BETTER_AUTH_SECRET (openssl rand -hex 32)
docker compose up -d --build

Open http://localhost:8080 and sign up. The schema is migrated automatically on every start and the data lives in the pgdata volume.

Put it on a domain

Run it behind a reverse proxy that terminates HTTPS (Caddy, nginx, Traefik, a load balancer) and set PUBLIC_URL in .env to the public address, for example https://status.example.com. Cookies, OAuth and links in emails all use this value, so sign-in will not work from a different origin than the one configured.

Settings (.env)

VariableMeaning
POSTGRES_PASSWORDRequired. Password of the bundled Postgres.
BETTER_AUTH_SECRETRequired. Signs sessions. Generate with openssl rand -hex 32 and keep it stable.
PUBLIC_URLPublic origin. Default http://localhost:8080.
PORTHost port. Default 8080.
DISABLE_SIGNUPSet to true to close registration once your own account exists. Invited people can still join.
LEGAL_LINKSSet to true to add "you agree to the Terms and Privacy Policy" to the sign-up form. The bundled /terms and /privacy pages describe the hosted service at openuptime.app: replace them with your own text first.
TURNSTILE_SITE_KEY
TURNSTILE_SECRET_KEY
Set both to put a Cloudflare Turnstile check on the email sign-up form; the API verifies the token too. GitHub sign-in is not covered.
INVITE_TTL_DAYSHow long invitations stay valid. Default 7.
CRON_SECRETOptional. Lets an external scheduler call POST /internal/run-checks; unset leaves /internal/* closed.
ALLOW_PRIVATE_TARGETSSet to true to monitor internal services. By default monitors and alert webhooks pointing at private, loopback or link-local addresses (and single-label names such as compose service names) are refused, so a signed-up user cannot probe your network.
CHECK_USER_AGENTOptional. User-Agent of HTTP checks.
SELFCHECK_URLSOptional. Comma-separated URLs a failed check fetches to tell a down target from an offline server. Unset uses three public sites; empty turns it off.
PROBE_REGIONS
PROBE_SECRET
Optional. Remote probes for multi-region checks. Unset, every check runs from this deployment.
EMAIL_FROM
+ one transport
Optional outgoing email. Transport is RESEND_API_KEY, SMTP_URL (smtps://user:pass@host:465) or SMTP_HOST / SMTP_PORT / SMTP_USER / SMTP_PASS (SMTP_SECURE=true for port 465). Without it emails are written to the container log.
GITHUB_CLIENT_ID
GITHUB_CLIENT_SECRET
Optional "Sign in with GitHub". Setup and troubleshooting.
PLAUSIBLE_DOMAIN
PLAUSIBLE_SRC
Optional Plausible analytics. Off when the domain is empty.

Operate

  • Upgrade: with the published image, change the tag in OPENUPTIME_IMAGE if you pinned one, then docker compose pull && docker compose up -d. Built from source: pull the new code, then docker compose up -d --build. Migrations run on start.
  • Backup: docker compose exec -T postgres pg_dump -U openuptime -Fc openuptime > openuptime.dump. Restore steps are in Backup and restore.
  • Several containers: checks are leased with FOR UPDATE SKIP LOCKED, so more containers can share one database without duplicating checks.
  • Logs: docker compose logs -f openuptime. A health endpoint is at /health.

Cloudflare Workers

Two Workers: openuptime-api (the API under /api/*, the minute cron and the queue consumer) and openuptime-web (the site, which reaches the API through a service binding).

Requirements

  • A Cloudflare account and a domain on Cloudflare. The Workers Paid plan is needed only for the Queue mode below; the Free plan works in inline mode at small scale
  • A Postgres database reachable from Cloudflare. It is accessed through Hyperdrive, so any hosted Postgres works (Neon, Supabase, RDS, your own)
  • Node.js 22+ and pnpm (corepack enable gives you the pinned version). Wrangler is installed with the project; sign in with pnpm exec wrangler login in apps/api

1. Get the code

git clone https://github.com/becoolme/openuptime.git
cd openuptime
pnpm install

2. Choose how checks run, then create Hyperdrive

Checks run in one of two modes. The mode follows from whether the queues block exists in apps/api/wrangler.jsonc, so it is a config switch, not a code change.

ModePlanWhat it does
Queue (default)Workers PaidThe cron fans due monitors out to a Queue, 25 per message, and the consumer runs them in parallel invocations. Scales to thousands of monitors.
InlineFree or PaidNo Queue. The minute cron runs the checks itself, up to 40 monitors per minute, within the Free plan's 50-subrequest and 10 ms CPU limits. Small installs only.

Queue mode (the file ships this way): create the queue once.

pnpm exec wrangler queues create openuptime-checks

Inline mode: delete the whole "queues" block from apps/api/wrangler.jsonc and skip the command above. Without a bound queue the Worker detects it and runs checks inline.

Then create Hyperdrive and copy its id into the hyperdrive block of apps/api/wrangler.jsonc:

pnpm exec wrangler hyperdrive create openuptime-prod --connection-string="postgres://user:pass@host:5432/db"

3. Create the schema

DATABASE_URL="postgres://user:pass@host:5432/db" pnpm db:migrate

It never issues CREATE SCHEMA, so a database role without database-level CREATE works too. Run it again after every upgrade.

Before an upgrade you can check the database without changing it: DATABASE_URL="postgres://user:pass@host:5432/db" pnpm --filter @openuptime/db-pg exec node migrate-plain.mjs --check verifies the applied history matches this version and lists the migrations that would run. Migrations run in one transaction, so CREATE INDEX CONCURRENTLY is not supported, and an enum value added in one migration cannot be used by a later migration in the same run.

4. Point the config at your domain

In apps/api/wrangler.jsonc set routes (your-domain/api/*), BETTER_AUTH_URL and WEB_ORIGIN (both https://your-domain) and EMAIL_FROM. Remove the placement block, or set it to your own database host.

In apps/web/wrangler.jsonc set the custom-domain routes pattern and PRODUCT_URL (where "Powered by" links to; use your own origin).

5. Secrets

cd apps/api
pnpm exec wrangler secret put BETTER_AUTH_SECRET     # openssl rand -hex 32
pnpm exec wrangler secret put CRON_SECRET            # any long random string; guards /internal/*
# optional "Sign in with GitHub": wrangler secret put GITHUB_CLIENT_ID, then GITHUB_CLIENT_SECRET (see the GitHub sign-in section)

6. Deploy

cd apps/api && pnpm exec wrangler deploy
cd ../web && pnpm build && pnpm exec wrangler deploy

Deploy the API first: the web Worker binds to it. Then open your domain and sign up.

Settings

WhereVariableMeaning
api varsBETTER_AUTH_URL
WEB_ORIGIN
Public origin of the site. Used for cookies, OAuth and email links.
api varsEMAIL_FROMSender address. Onboard the domain in Cloudflare Email Sending; without it emails are logged.
api varsINVITE_TTL_DAYSHow long invitations stay valid. Default 7.
api varsALLOW_PRIVATE_TARGETSSet to true to let monitors and alert webhooks target private addresses. Default: refused. Cloudflare Workers cannot reach private ranges anyway; this mostly matters for Docker.
api vars + secretPROBE_REGIONS, PROBE_SECRETOptional. Remote probes for multi-region checks. Put the region list in vars and the shared secret with wrangler secret put PROBE_SECRET.
api varsDISABLE_SIGNUPSet to true to close registration (email and GitHub). Create your own account first; afterwards only people with a pending invitation can still sign up.
api varsLEGAL_LINKSSet to true to add "you agree to the Terms and Privacy Policy" to the sign-up form. The bundled /terms and /privacy pages describe the hosted service at openuptime.app: replace them with your own text first.
api vars + secretTURNSTILE_SITE_KEY, TURNSTILE_SECRET_KEYOptional. Put the site key in the API vars and the secret key with wrangler secret put TURNSTILE_SECRET_KEY; email sign-up then requires a verified Turnstile token. Both must be set.
api secretsBETTER_AUTH_SECRET
CRON_SECRET
See step 5.
web varsPRODUCT_URLTarget of the "Powered by" link on status pages.
web varsPLAUSIBLE_DOMAIN
PLAUSIBLE_SRC
Optional analytics. Off when the domain is unset.

How checks run

A cron trigger fires every minute and leases the monitors that are due. In Queue mode it packs them 25 per message into the openuptime-checks Queue, and the queue consumer runs each pack, records results, opens and resolves incidents and sends alerts. In inline mode the cron does all of that itself for up to 40 monitors per run. Checks every 30 seconds need Queue mode: the cron looks one minute ahead and the queue delays each message to its slot, while inline mode can only run what is already due, so those monitors effectively run once a minute. A monitor checked less often than once a minute runs at a fixed offset within its interval, derived from its id, so monitors created together do not all run in the same minute.

Upgrade

Pull the new code, run the migration again (it only applies what is new), then deploy the API and the web Worker in that order.

Switching modes later

  • Free to Paid: upgrade the plan, restore the queues block, run pnpm exec wrangler queues create openuptime-checks, then pnpm exec wrangler deploy the API.
  • Paid to Free: remove the queues block and deploy the API again. You can delete the queue afterwards.

No data migration is involved. Monitors, history and incidents are untouched.

Multi-region checks

By default a monitor is checked from where OpenUptime runs. To check from several places, deploy the small probe in apps/probe to a few regions and tell the API where they are. A monitor uses them only when you pick regions for it; everything else keeps running from this deployment, so nothing changes until you opt in. How a verdict is reached and what the app shows are covered in Multi-region checks.

  1. Deploy the probe in each place you want checks to come from. It is a small service that runs one check on request, and there are two ways to run it. Pick whichever fits, or mix them: every probe is just a URL to the API.

Option A: Docker or any Node host

The probe is a plain Node server, so it runs on any VPS or machine in any country. The image is built from the repository root:

docker build -f apps/probe/Dockerfile -t openuptime-probe .
docker run -d --restart unless-stopped -p 8787:8787 \
  -e PROBE_SECRET=<a long random string> -e PROBE_REGION=sao-paulo \
  openuptime-probe

apps/probe/docker-compose.yml wraps it (it builds the image from this repository, or pulls ghcr.io/becoolme/openuptime-probe once one is published) and can add HTTPS with Caddy: PROBE_DOMAIN=probe-sao.example.com docker compose --profile tls up -d. Without Docker, run pnpm --filter @openuptime/probe build:node and then PROBE_SECRET=… node apps/probe/dist/server.mjs (Node 22). The API needs an https URL, so put the probe behind a reverse proxy or the bundled Caddy. Docker and Node probes answer GET / with {"ok":true,"region":"…"} for health checks; on Vercel the same answer is at /api/probe/<id> and the root path is a 404.

Settings: PROBE_SECRET (required), PROBE_REGION (a label), PORT (default 8787), HOST (default 0.0.0.0), CHECK_USER_AGENT (same as on the API). Private and internal targets are refused unless you set ALLOW_PRIVATE_TARGETS=true on that probe, which is what lets a probe inside your office or home network check internal services. Only do it for a probe that lives in the network you want to watch.

Option B: Vercel, several regions at once

The bundled build creates one function per region (apps/probe/regions.json, default: Virginia, San Francisco, Frankfurt, Singapore, Tokyo). Set PROBE_SECRET on the Vercel project, run pnpm build:vercel in apps/probe, then vercel deploy --prebuilt --prod. Running a function in several regions needs a Vercel plan that allows it.

  1. Tell the API. Set the same secret as PROBE_SECRET and list the regions as JSON in PROBE_REGIONS:
PROBE_SECRET=<the same secret as on the probe>
PROBE_REGIONS={"us-east":"https://probe.example.app/api/probe/us-east","eu-central":"https://probe.example.app/api/probe/eu-central","ap-southeast":{"url":"https://probe.example.app/api/probe/ap-southeast","name":"Singapore"}}

Keys are region ids you choose (lowercase letters, digits and dashes). A value is a URL, or { "url", "name" } to set the label shown in the app. URLs must be https (plain http is accepted for localhost only). The list appears in the app and in GET /api/regions, and a monitor can then pick up to its plan's limit.

How it behaves

  • Only HTTP, TCP and WebSocket monitors can use regions. Other types, and heartbeats, always run from this deployment.
  • With several regions a run counts as failed only when most of the regions that answered failed, so one region's bad route does not open an incident. Each region's result is kept, and the monitor page shows uptime and latency per region.
  • A probe that cannot be reached is not a failed check. It is left out of the vote, and when no probe answers the check runs from this deployment instead, so a probe outage cannot blind monitoring.
  • Each region counts as one check against any check allowance. A single request can also be sent from one region on the monitor page (or POST /api/monitors/:id/check with a region); it is not recorded and does not change the monitor's status.
  • Probes only accept signed requests (HMAC-SHA256 over timestamp and body, 60 s skew) and refuse private, loopback and link-local targets whatever the signature (unless its own operator turns ALLOW_PRIVATE_TARGETS on), so a probe cannot be used as an open proxy.

GitHub sign-in

"Continue with GitHub" is optional and off until you configure a GitHub OAuth App. Without it the GitHub button is hidden everywhere (web and mobile app) and email sign-in keeps working unchanged.

1. Create the OAuth App

In GitHub, open Settings → Developer settings → OAuth Apps → New OAuth App (or the same page of an organization). Fill in:

  • Homepage URL: your public address, for example https://status.example.com.
  • Authorization callback URL: <BETTER_AUTH_URL>/api/auth/callback/github, exactly. With Docker BETTER_AUTH_URL is your PUBLIC_URL; on Cloudflare it is the BETTER_AUTH_URL var of the API Worker, the public origin of the site (the API is served at /api on the same domain). Example: https://status.example.com/api/auth/callback/github.

Create a client secret and keep both values.

2. Set the two variables

  • Docker: add GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET to .env, then docker compose up -d.
  • Cloudflare: in apps/api run pnpm exec wrangler secret put GITHUB_CLIENT_ID and pnpm exec wrangler secret put GITHUB_CLIENT_SECRET, then redeploy the API Worker.

3. Check it

curl https://status.example.com/api/config
# "auth": { ..., "github": true, ... }

Both variables must be set; with only one, github stays false. Signed-in users can then connect or disconnect GitHub under Account → Connected accounts, even when the GitHub email differs from the account email. A GitHub login is only matched to an existing account by email when GitHub reports that address as verified, and an account always keeps at least one way to sign in. DISABLE_SIGNUP also applies to first-time GitHub sign-ins.

A first GitHub sign-in creates the account and its personal workspace; it has no password. To add one, use Forgot password with the GitHub email (this needs outgoing email to be configured). Deleting such an account needs a recent sign-in instead of a password.

The mobile app uses the same provider: it reads auth.github from /api/config and opens the same OAuth App through /api/auth/native/github, so there is nothing extra to register (see native sign-in).

Troubleshooting

  • "redirect_uri is not associated with this application": the callback URL in the OAuth App differs from <BETTER_AUTH_URL>/api/auth/callback/github (scheme, host, port or path). Fix it in GitHub, not in the app.
  • The callback goes to the wrong host: BETTER_AUTH_URL (PUBLIC_URL in Docker) is wrong, often still localhost. Set it to the public address and restart.
  • Behind a proxy: terminate HTTPS at the proxy and pass the original Host and X-Forwarded-Proto headers. The public address configured above is what GitHub must be given.
  • Button missing: /api/config shows github: false, so a variable is empty or the service was not restarted.
  • "Sign-ups are closed": DISABLE_SIGNUP=true; invite the person first, or connect GitHub from an existing account.

iOS push notifications (APNs)

The OpenUptime iOS app can receive alerts as push notifications. The server sends them through Apple's APNs, so it needs an APNs credential. Push is off until all four variables below are set; GET /api/config then reports push.apns: true and the Mobile app (push) channel type appears under Alerting.

What you need

  • An Apple Developer account and an App ID for the app, with the Push Notifications capability.
  • An APNs Auth Key (a .p8 file) from Certificates, Identifiers & Profiles → Keys, with its Key ID.
  • Your Team ID and the app's bundle id.
VariableValue
APNS_KEYThe contents of the .p8 file. A literal \n in place of line breaks is accepted, which is handy in .env files.
APNS_KEY_IDThe key's 10-character id.
APNS_TEAM_IDYour Apple Developer team id.
APNS_BUNDLE_IDThe app's bundle id, used as the APNs topic.
  • Docker: add the four variables to .env and run docker compose up -d.
  • Cloudflare: in apps/api run pnpm exec wrangler secret put APNS_KEY (paste the whole file), then the same for APNS_KEY_ID, APNS_TEAM_ID and APNS_BUNDLE_ID, and redeploy the API Worker.

How it works

People register their phone from the app; a push channel then alerts every member of the workspace who has a registered device, each in their own language. Registering a phone as an owner or admin creates a Mobile app channel for you if the workspace has none. Phones that Apple reports as no longer valid are forgotten automatically.

Important: an APNs key is tied to your Apple team and the app's bundle id, and a phone's token only works with the app that produced it. The official OpenUptime app can therefore receive push only from the hosted service. On a self-hosted server push works for an app you build and sign yourself with your own bundle id and key. A relay that would let the official app receive push from self-hosted servers is not implemented.

After install

  • Create your first monitor, then a status page and, optionally, embed its state on your site.
  • Automate with the API or connect an agent through MCP. Use your own domain in the examples.

自托管 OpenUptime

在 Cloudflare Workers 或 Docker 上运行你自己的实例。两种方式使用同一套代码和一个由你掌控的 Postgres 数据库。

二选一:

  • Docker:一个容器加 Postgres,任意机器可跑,最适合快速试用。
  • Cloudflare Workers:两个 Worker,加 Queue 和连接 Postgres 的 Hyperdrive,从 Cloudflare 网络发起检测。

Docker

一个容器同时运行 API、网页应用和检测调度器,compose 文件会一并启动 Postgres。

环境要求

  • Docker 和 Compose v2
  • 能访问被监控服务的机器

启动

方式 A:直接使用发布的镜像。发布版本会推送到 ghcr.io/becoolme/openuptime(支持 linux/amd64 和 linux/arm64),无需克隆代码,也无需构建。

mkdir openuptime && cd openuptime
curl -fsSLO https://raw.githubusercontent.com/becoolme/openuptime/main/docker-compose.yml
curl -fsSL https://raw.githubusercontent.com/becoolme/openuptime/main/.env.docker.example -o .env
# 编辑 .env:设置 POSTGRES_PASSWORD 和 BETTER_AUTH_SECRET(openssl rand -hex 32),
# 并取消 OPENUPTIME_IMAGE 的注释(固定版本 ghcr.io/becoolme/openuptime:0.1.0,或跟随 :latest)
docker compose pull && docker compose up -d

方式 B:从源码构建。

git clone https://github.com/becoolme/openuptime.git
cd openuptime
cp .env.docker.example .env
# 编辑 .env:设置 POSTGRES_PASSWORD 和 BETTER_AUTH_SECRET(openssl rand -hex 32)
docker compose up -d --build

打开 http://localhost:8080 注册即可。数据库结构在每次启动时自动迁移,数据保存在 pgdata 卷中。

绑定域名

在能终止 HTTPS 的反向代理(Caddy、nginx、Traefik、负载均衡器)后面运行,并把 .env 里的 PUBLIC_URL 设为公网地址,例如 https://status.example.com。Cookie、OAuth 和邮件里的链接都使用该值,用与配置不一致的域名访问会无法登录。

配置项(.env)

变量说明
POSTGRES_PASSWORD必填。内置 Postgres 的密码。
BETTER_AUTH_SECRET必填。用于签名会话。用 openssl rand -hex 32 生成,并保持不变。
PUBLIC_URL公网地址,默认 http://localhost:8080。
PORT宿主机端口,默认 8080。
DISABLE_SIGNUP设为 true 关闭注册(请先创建好自己的账号),受邀的人仍可加入。
LEGAL_LINKS设为 true 后,注册表单会显示“创建账户即表示同意服务条款与隐私政策”。自带的 /terms 和 /privacy 描述的是 openuptime.app 托管服务,请先换成你自己的文本。
TURNSTILE_SITE_KEY
TURNSTILE_SECRET_KEY
两者都设置后,邮箱注册表单会显示 Cloudflare Turnstile 验证,API 也会校验令牌。GitHub 登录不受影响。
INVITE_TTL_DAYS邀请有效天数,默认 7。
CRON_SECRET可选。允许外部调度器调用 POST /internal/run-checks;不设置则 /internal/* 保持关闭。
ALLOW_PRIVATE_TARGETS设为 true 以监控内网服务。默认拒绝指向私有、回环、链路本地地址(以及 compose 服务名这类单段主机名)的监控项和告警 Webhook,避免已注册用户探测你的内网。
CHECK_USER_AGENT可选。HTTP 检查使用的 User-Agent。
SELFCHECK_URLS可选。检查失败时用来区分“目标故障”与“服务器断网”的网址,逗号分隔。不设置则使用三个公共站点;留空则关闭。
PROBE_REGIONS
PROBE_SECRET
可选。用于多区域检测的远程探针。不设置时,所有检测都从本部署发起。
EMAIL_FROM
+ 一种发信方式
可选的发信配置。方式为 RESEND_API_KEY、SMTP_URL(smtps://user:pass@host:465)或 SMTP_HOST / SMTP_PORT / SMTP_USER / SMTP_PASS(465 端口加 SMTP_SECURE=true)。不配置时邮件只写入容器日志。
GITHUB_CLIENT_ID
GITHUB_CLIENT_SECRET
可选,启用 GitHub 登录。配置与排错。
PLAUSIBLE_DOMAIN
PLAUSIBLE_SRC
可选的 Plausible 统计。域名为空则关闭。

运维

  • 升级:使用发布镜像时,若固定了版本就修改 OPENUPTIME_IMAGE 的标签,再执行 docker compose pull && docker compose up -d;从源码构建时拉取新代码后执行 docker compose up -d --build。迁移在启动时自动运行。
  • 备份:docker compose exec -T postgres pg_dump -U openuptime -Fc openuptime > openuptime.dump。恢复步骤见备份与恢复。
  • 多个容器:检测通过 FOR UPDATE SKIP LOCKED 加租约,多个容器共用一个数据库也不会重复检测。
  • 日志:docker compose logs -f openuptime。健康检查接口为 /health。

Cloudflare Workers

两个 Worker:openuptime-api(/api/* 下的 API、每分钟的 cron 和队列消费者)和 openuptime-web(站点本身,通过 service binding 访问 API)。

环境要求

  • 一个 Cloudflare 账号,以及托管在 Cloudflare 的域名。只有下文的 Queue 模式需要 Workers 付费版;免费版可用内联模式,适合小规模
  • 一个 Cloudflare 能访问的 Postgres 数据库。通过 Hyperdrive 连接,所以 Neon、Supabase、RDS 或自建均可
  • Node.js 22+ 和 pnpm(corepack enable 会装好指定版本)。Wrangler 随项目安装,在 apps/api 中执行 pnpm exec wrangler login 登录

1. 获取代码

git clone https://github.com/becoolme/openuptime.git
cd openuptime
pnpm install

2. 选择检测运行方式,并创建 Hyperdrive

检测有两种运行模式,是否保留 apps/api/wrangler.jsonc 里的 queues 配置块决定使用哪一种,只是配置切换,不需要改代码。

模式套餐说明
Queue(默认)Workers 付费版cron 把到期的监控项按每 25 个一条消息放入 Queue,由消费者并行执行,可扩展到数千个监控项。
内联免费版或付费版不用 Queue。每分钟的 cron 自己执行检测,每次最多 40 个监控项,受免费版 50 个子请求和 10 ms CPU 限制,仅适合小规模。

Queue 模式(配置文件默认如此):创建一次队列。

pnpm exec wrangler queues create openuptime-checks

内联模式:从 apps/api/wrangler.jsonc 中删除整个 "queues" 配置块,并跳过上面的命令。没有绑定队列时 Worker 会自动改为内联执行。

然后创建 Hyperdrive,把得到的 id 填进 apps/api/wrangler.jsonc 的 hyperdrive 配置块:

pnpm exec wrangler hyperdrive create openuptime-prod --connection-string="postgres://user:pass@host:5432/db"

3. 创建数据库结构

DATABASE_URL="postgres://user:pass@host:5432/db" pnpm db:migrate

它不会执行 CREATE SCHEMA,所以没有数据库级 CREATE 权限的角色也能运行。每次升级后重新执行即可。

升级前可以只读检查数据库:DATABASE_URL="postgres://user:pass@host:5432/db" pnpm --filter @openuptime/db-pg exec node migrate-plain.mjs --check 会验证已执行的迁移历史与当前版本一致,并列出将要执行的迁移,不会修改数据库。迁移在同一个事务中执行,因此不支持 CREATE INDEX CONCURRENTLY,同一次运行中也不能使用前一个迁移刚新增的枚举值。

4. 把配置指向你的域名

在 apps/api/wrangler.jsonc 中设置 routes(你的域名/api/*)、BETTER_AUTH_URL 和 WEB_ORIGIN(都填 https://你的域名)以及 EMAIL_FROM。删除 placement 块,或改成你自己的数据库主机。

在 apps/web/wrangler.jsonc 中设置自定义域名的 routes,以及 PRODUCT_URL("Powered by" 链接的目标,填你自己的地址)。

5. 密钥

cd apps/api
pnpm exec wrangler secret put BETTER_AUTH_SECRET     # openssl rand -hex 32
pnpm exec wrangler secret put CRON_SECRET            # 任意足够长的随机字符串,保护 /internal/*
# 可选:GITHUB_CLIENT_ID 和 GITHUB_CLIENT_SECRET,用于 GitHub 登录

6. 部署

cd apps/api && pnpm exec wrangler deploy
cd ../web && pnpm build && pnpm exec wrangler deploy

务必先部署 API:web Worker 依赖它。然后打开你的域名注册即可。

配置项

位置变量说明
api varsBETTER_AUTH_URL
WEB_ORIGIN
站点公网地址,用于 Cookie、OAuth 和邮件链接。
api varsEMAIL_FROM发件地址。需在 Cloudflare Email Sending 中接入该域名;不配置则邮件只写日志。
api varsINVITE_TTL_DAYS邀请有效天数,默认 7。
api varsALLOW_PRIVATE_TARGETS设为 true 允许监控项和告警 Webhook 指向私有地址,默认拒绝。Cloudflare Workers 本身无法访问私有网段,此项主要影响 Docker 部署。
api vars + secretPROBE_REGIONS, PROBE_SECRET可选。用于多区域检测的远程探针。区域列表放在 vars,共享密钥用 wrangler secret put PROBE_SECRET 设置。
api varsDISABLE_SIGNUP设为 true 关闭注册(邮箱与 GitHub 均适用)。请先创建好自己的账号;之后只有持有待处理邀请的人还能注册。
api varsLEGAL_LINKS设为 true 后,注册表单会显示“创建账户即表示同意服务条款与隐私政策”。自带的 /terms 和 /privacy 描述的是 openuptime.app 托管服务,请先换成你自己的文本。
api vars + secretTURNSTILE_SITE_KEY、TURNSTILE_SECRET_KEY可选。站点密钥放进 API 的 vars,私钥用 wrangler secret put TURNSTILE_SECRET_KEY 设置;之后邮箱注册需要通过 Turnstile 验证。两者必须同时设置。
api secretsBETTER_AUTH_SECRET
CRON_SECRET
见第 5 步。
web varsPRODUCT_URL状态页 "Powered by" 链接的目标。
web varsPLAUSIBLE_DOMAIN
PLAUSIBLE_SRC
可选统计。未设置域名则关闭。

检测如何运行

cron 每分钟触发一次并租约到期的监控项。Queue 模式下每 25 个打包成一条消息放入 openuptime-checks 队列,由消费者执行每个分组,记录结果、开启和解决事件并发送告警。内联模式下这些都由 cron 自己完成,每次最多 40 个监控项。检测间隔超过一分钟的监控项会在间隔内一个固定的时间点运行(由监控项 ID 决定),因此同时创建的监控项不会都挤在同一分钟检测。

升级

拉取新代码,重新执行迁移(只会应用新增的部分),然后先部署 API、再部署 web Worker。

之后切换模式

  • 免费版升级到付费版:升级套餐,恢复 queues 配置块,执行 pnpm exec wrangler queues create openuptime-checks,再 pnpm exec wrangler deploy API。
  • 付费版降到免费版:删除 queues 配置块并重新部署 API,之后可以删除队列。

不涉及数据迁移,监控项、历史记录和事件都不受影响。

多区域检测

默认情况下,监控项从 OpenUptime 自身所在位置发起检测。想从多个地点检测,可把 apps/probe 中的小型探针部署到几个区域,再把它们的地址告诉 API。只有你为某个监控项指定了区域,才会使用探针;其他监控项仍从本部署发起,因此不主动开启就不会有任何变化。结论如何得出、应用里能看到什么,见多区域检测。

  1. 部署探针到你想让检测发起的每个地点。探针是个小服务,按请求执行一次检测,有两种运行方式,可任选或混用:对 API 来说每个探针只是一个 URL。

方式 A:Docker 或任意 Node 主机

探针就是一个普通的 Node 服务,可以跑在任何国家的任意 VPS 或机器上。镜像在仓库根目录构建:

docker build -f apps/probe/Dockerfile -t openuptime-probe .
docker run -d --restart unless-stopped -p 8787:8787 \
  -e PROBE_SECRET=<一段足够长的随机字符串> -e PROBE_REGION=sao-paulo \
  openuptime-probe

apps/probe/docker-compose.yml 对它做了封装(会用本仓库构建镜像;一旦发布了 ghcr.io/becoolme/openuptime-probe,则直接拉取),并可用 Caddy 自动加上 HTTPS:PROBE_DOMAIN=probe-sao.example.com docker compose --profile tls up -d。不用 Docker 时,运行 pnpm --filter @openuptime/probe build:node,再 PROBE_SECRET=… node apps/probe/dist/server.mjs(Node 22)。API 需要 https 地址,所以请把探针放在反向代理或自带的 Caddy 后面。Docker 和 Node 探针对 GET / 返回 {"ok":true,"region":"…"},可用于健康检查;Vercel 上同样的响应在 /api/probe/<id>,根路径是 404。

配置项:PROBE_SECRET(必填)、PROBE_REGION(标签)、PORT(默认 8787)、HOST(默认 0.0.0.0)、CHECK_USER_AGENT(与 API 上的含义相同)。默认拒绝私有和内部地址;只有在该探针上设置 ALLOW_PRIVATE_TARGETS=true 才允许,这样就可以把探针放在办公室或家里的内网中,检测内部服务。请只对确实位于被监控网络内的探针这样做。

方式 B:Vercel,一次部署多个区域

自带的构建会为每个区域生成一个函数(apps/probe/regions.json,默认:弗吉尼亚、旧金山、法兰克福、新加坡、东京)。在 Vercel 项目上设置 PROBE_SECRET,在 apps/probe 中运行 pnpm build:vercel,再 vercel deploy --prebuilt --prod。让函数在多个区域运行,需要允许这一点的 Vercel 套餐。

  1. 告诉 API。把同一个密钥设为 PROBE_SECRET,并用 JSON 在 PROBE_REGIONS 中列出区域:
PROBE_SECRET=<与探针相同的密钥>
PROBE_REGIONS={"us-east":"https://probe.example.app/api/probe/us-east","eu-central":"https://probe.example.app/api/probe/eu-central","ap-southeast":{"url":"https://probe.example.app/api/probe/ap-southeast","name":"Singapore"}}

键是你自己定的区域 id(小写字母、数字和连字符)。值可以是 URL,或 { "url", "name" } 以设置在应用中显示的名称。URL 必须是 https。区域列表会出现在应用和 GET /api/regions 中,监控项可在套餐上限内选择多个区域。

行为说明

  • 只有 HTTP、TCP 和 WebSocket 监控项可以使用区域。其他类型和心跳始终从本部署发起。
  • 选择多个区域时,只有多数应答的区域都失败才判定为失败,单个区域的线路问题不会产生事件。各区域的结果都会保留,监控详情页按区域显示可用率和延迟。
  • 探针无法连通不算检测失败:它不参与表决;所有探针都没有应答时,改为从本部署发起检测,因此探针故障不会让监控失明。
  • 每个区域各计一次检查额度。也可以在监控详情页(或 POST /api/monitors/:id/check 并传 region)从某一个区域单次发起请求;该请求不会被记录,也不会改变监控状态。
  • 探针只接受签名请求(对时间戳与请求体做 HMAC-SHA256,允许 60 秒偏差),并且无论签名是否有效,都会拒绝私有、回环和链路本地地址(除非该探针的运维者自己打开 ALLOW_PRIVATE_TARGETS),因此不会变成开放代理。

GitHub 登录

“使用 GitHub 继续”是可选功能,配置 GitHub OAuth App 后才会启用。未配置时,网页和移动应用都不会显示 GitHub 按钮,邮箱登录照常使用。

1. 创建 OAuth App

在 GitHub 打开 Settings → Developer settings → OAuth Apps → New OAuth App(组织账号在其对应页面)。填写:

  • Homepage URL:你的公网地址,例如 https://status.example.com。
  • Authorization callback URL:必须精确为 <BETTER_AUTH_URL>/api/auth/callback/github。Docker 中 BETTER_AUTH_URL 即 PUBLIC_URL;Cloudflare 上是 API Worker 的 BETTER_AUTH_URL 变量,即站点公网地址(API 在同一域名的 /api 下)。例如 https://status.example.com/api/auth/callback/github。

创建 Client secret,并保存这两个值。

2. 设置两个变量

  • Docker:把 GITHUB_CLIENT_ID 和 GITHUB_CLIENT_SECRET 写入 .env,然后执行 docker compose up -d。
  • Cloudflare:在 apps/api 中执行 pnpm exec wrangler secret put GITHUB_CLIENT_ID 和 pnpm exec wrangler secret put GITHUB_CLIENT_SECRET,然后重新部署 API Worker。

3. 验证

curl https://status.example.com/api/config
# "auth": { ..., "github": true, ... }

两个变量必须同时设置,只设一个时 github 仍为 false。之后已登录的用户可以在 账号 → 已关联的账号 中关联或取消关联 GitHub,GitHub 邮箱可以与账号邮箱不同。只有 GitHub 报告该邮箱已验证时,GitHub 登录才会按邮箱匹配已有账号;账号始终至少保留一种登录方式。DISABLE_SIGNUP 同样适用于首次 GitHub 登录。

首次 GitHub 登录会创建账号和个人工作区,此时没有密码。需要密码时,用 GitHub 邮箱走“忘记密码”即可设置(需要已配置发信)。这类账号删除时不需要密码,只要求最近登录过。

移动应用使用同一个提供方:它从 /api/config 读取 auth.github,并通过 /api/auth/native/github 走同一个 OAuth App,无需额外注册(见原生登录)。

排错

  • “redirect_uri is not associated with this application”:OAuth App 中的回调地址与 <BETTER_AUTH_URL>/api/auth/callback/github 不一致(协议、主机、端口或路径)。请在 GitHub 中修改。
  • 回调跳到了错误的主机:BETTER_AUTH_URL(Docker 中为 PUBLIC_URL)设置有误,常见是仍为 localhost。改成公网地址并重启。
  • 位于反向代理之后:在代理处终止 HTTPS,并传递原始的 Host 与 X-Forwarded-Proto 请求头。给 GitHub 填写的应是上面配置的公网地址。
  • 看不到按钮:/api/config 显示 github: false,说明变量为空或服务未重启。
  • “Sign-ups are closed”:已设置 DISABLE_SIGNUP=true;请先邀请对方,或在已有账号中关联 GitHub。

iOS 推送通知(APNs)

OpenUptime iOS 应用可以通过推送接收告警。服务器经由 Apple 的 APNs 发送,因此需要 APNs 凭证。以下四个变量全部设置后才会启用推送;此时 GET /api/config 会返回 push.apns: true,告警页里也会出现 手机 App 推送 渠道类型。

你需要准备

  • 一个 Apple Developer 账号,以及为应用创建的 App ID(开启 Push Notifications 能力)。
  • 在 Certificates, Identifiers & Profiles → Keys 中创建的 APNs Auth Key(.p8 文件)及其 Key ID。
  • 你的 Team ID 和应用的 bundle id。
变量取值
APNS_KEY.p8 文件的内容。可以用字面的 \n 代替换行,写在 .env 里更方便。
APNS_KEY_ID密钥的 10 位 id。
APNS_TEAM_IDApple Developer 团队 id。
APNS_BUNDLE_ID应用的 bundle id,用作 APNs topic。
  • Docker:把四个变量写进 .env,然后执行 docker compose up -d。
  • Cloudflare:在 apps/api 中执行 pnpm exec wrangler secret put APNS_KEY(粘贴整个文件),再对 APNS_KEY_ID、APNS_TEAM_ID、APNS_BUNDLE_ID 做同样操作,然后重新部署 API Worker。

工作方式

成员在应用里注册自己的手机;push 渠道会通知工作区中所有已注册设备的成员,并按各自的语言显示。所有者或管理员注册手机时,如果工作区还没有该渠道,会自动创建名为 Mobile app 的渠道。Apple 反馈已失效的手机会被自动清除。

重要:APNs 密钥绑定你的 Apple 团队和应用的 bundle id,手机令牌也只对产生它的应用有效。因此官方 OpenUptime 应用只能接收托管服务发出的推送。自托管服务器上,推送适用于你自己用自己的 bundle id 和密钥构建并签名的应用。让官方应用接收自托管服务器推送的中继服务尚未实现。

安装之后

  • 创建第一个监控项,再创建状态页,需要的话把状态嵌入到你的网站。
  • 通过 API 自动化,或用 MCP 接入 Agent,示例里的域名换成你自己的。

Last updated 2026-11-02最后更新:2026-11-02