# Self-hosting QRdx

URL: https://qrdx.dev/docs/self-hosting
Source: https://github.com/qrdxinc/qrdx/blob/main/apps/docs/content/docs/self-hosting.mdx

Run the QRdx web app on your own server with Docker Compose or Node.js, with accounts, dynamic QR codes, analytics and hosted pages included.

By the end of this guide you will have QRdx running at your own URL: the QR editor, accounts, dynamic QR codes with scan analytics, hosted pages, workspaces and saved themes, on a Postgres database you control. The Docker Compose path takes about half an hour, most of it the first image build.

The web app is open source under the AGPL-3.0 license. The business features are not: workspace single sign-on, the audit log, the client portal and client reports, white-label pages with custom CSS, and conversion tracking live in the `ee/` folders under the QRdx commercial license and stay off unless you set a license key (`QRDX_EE_LICENSE`). Using them in production needs a written agreement with QRdx; see [LICENSING.md](https://github.com/qrdxinc/qrdx/blob/main/LICENSING.md). You don't need any of this to use the [`qrdx` React library](https://qrdx.dev/docs/getting-started) or the [CLI](https://qrdx.dev/docs/developers/cli): they run anywhere without a backend, under the MIT license. [Open source at QRdx](https://qrdx.dev/open-source-qr-code-generator) lists each part of the repository and its license.

QRdx issues the license key with the agreement. To get one, use the [enterprise page](https://qrdx.dev/enterprise) or email [enterprise@qrdx.dev](mailto:enterprise@qrdx.dev). The key has an expiry, and your server checks it offline against QRdx's public key, without calling QRdx. A value QRdx didn't sign, or a key more than 14 days past its expiry, leaves all of these features off, as if no key were set; the rest of QRdx, sign-in included, works as before. **Admin** → **Health** shows when your key expires, and the server log says at start-up whether it's valid.

**The Docker setup is new**

If a step doesn't work as written, [open an issue](https://github.com/qrdxinc/qrdx/issues) with the command you ran and its output.

## Before you start [#before-you-start]

- Docker with Compose v2 and BuildKit (Docker Desktop and current Docker Engine include both), or Node.js 22 (22.22.3 or later) and [Bun](https://bun.com/docs/installation) 1.4 for the manual setup.
- At least 8 GB of memory for Docker while the image builds.
- A way to sign in, so accounts can be created: a GitHub or Google OAuth app, or [Resend](https://resend.com) for email sign-in codes. Sign-in codes are emailed only when `NEXT_PUBLIC_APP_URL` isn't `localhost`. `bun run dev` prints them in the terminal instead, but the Docker image doesn't, so a local Docker test needs GitHub or Google sign-in. The sign-in page shows only the ways in that work on your server, and says sign-in isn't set up when none do. It still offers **Continue with passkey**, which works only for an account that already has a passkey.
- Postgres: the container bundled in `docker-compose.yml`, or a [Neon](https://neon.tech) database.
- For anything beyond a local test, a domain and a reverse proxy that terminates HTTPS.

The docs are not part of a self-hosted instance. Your instance sends every docs link (`/docs` and the pages under it, their Markdown copies and `/llms-full.txt`) to the same pages on qrdx.dev.

### How the database connection works [#how-the-database-connection-works]

The app talks to Postgres through Neon's serverless HTTP driver.

- **Neon:** works directly. Set `DATABASE_URL` to your Neon connection string.
- **Plain Postgres:** needs a Neon-compatible HTTP proxy in front of it. `docker-compose.yml` runs one ([local-neon-http-proxy](https://github.com/TimoWilhelm/local-neon-http-proxy)) and sets `DATABASE_HTTP_ENDPOINT` so the app sends its queries there.

The schema comes from `packages/database/schema.ts` and is applied with `drizzle-kit push`. There are no migration files to run by hand.

## Quick start with Docker Compose [#quick-start-with-docker-compose]

### 1. Clone the repository [#1-clone-the-repository]

```bash title="Terminal"
git clone https://github.com/qrdxinc/qrdx.git
cd qrdx
```

### 2. Configure the environment [#2-configure-the-environment]

Copy the example file to the repository root, where Compose reads it, and generate the session secret:

```bash title="Terminal"
cp apps/app/.env.example .env
openssl rand -base64 32
# prints a 44-character string: paste it as BETTER_AUTH_SECRET below
```

Open `.env` and set these values. Every other line can stay commented out.

```bash title=".env"
# Your instance's URL. For a local test use http://localhost:3000 and sign in
# with GitHub or Google: email codes aren't sent to a localhost instance.
NEXT_PUBLIC_APP_URL=https://qr.example.com
BETTER_AUTH_URL=https://qr.example.com
BETTER_AUTH_SECRET=<the string openssl printed>

# One sign-in provider. The callback URL for GitHub is
# <NEXT_PUBLIC_APP_URL>/api/auth/callback/github
GITHUB_CLIENT_ID=<client ID of your GitHub OAuth app>
GITHUB_CLIENT_SECRET=<its client secret>
```

Where each value comes from:

| Variable | Where to get it |
| --- | --- |
| `NEXT_PUBLIC_APP_URL` | The public URL of your instance, no trailing slash. Keep `http://localhost:3000` for a local test. |
| `BETTER_AUTH_URL` | The same value. Uncomment the line. |
| `BETTER_AUTH_SECRET` | The output of `openssl rand -base64 32`. |
| `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET` | A [GitHub OAuth app](https://github.com/settings/developers) whose callback URL is `<your url>/api/auth/callback/github`. |
| `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` | Instead of GitHub: a [Google OAuth client](https://console.cloud.google.com/apis/credentials) whose redirect URI is `<your url>/api/auth/callback/google`. |

Leave `DATABASE_URL` as it is: Compose points the app at its own Postgres container and ignores the value in `.env`. To change the database password, set `POSTGRES_PASSWORD` before the first start.

### 3. Start the stack [#3-start-the-stack]

```bash title="Terminal"
docker compose up -d --build
```

This builds the image, starts Postgres and the proxy, runs the one-shot `migrate` service (`drizzle-kit push`) and then starts the app on port 3000. The first build takes several minutes. When it's done, `docker compose ps -a` lists the four services (plain `docker compose ps` leaves out `migrate` once it has exited):

```text title="docker compose ps -a (columns trimmed)"
NAME              SERVICE    STATUS
qrdx-app-1        app        Up 16 seconds
qrdx-db-1         db         Up 23 seconds (healthy)
qrdx-db-proxy-1   db-proxy   Up 17 seconds
qrdx-migrate-1    migrate    Exited (0) 16 seconds ago
```

`migrate` is meant to exit: it syncs the schema and stops. To watch the schema sync and the app start:

```bash title="Terminal"
docker compose logs -f migrate app
```

### 4. Sign in [#4-sign-in]

Open `NEXT_PUBLIC_APP_URL` in a browser and sign in with a method you set up in step 2: GitHub or Google, or an email code if you set up [Resend](https://qrdx.dev/docs/notifications#self-hosting) and `NEXT_PUBLIC_APP_URL` isn't `localhost`. Your account is created on first sign-in. Without one of these, nobody can create an account.

### 5. Make yourself an admin [#5-make-yourself-an-admin]

Add the email address of the account you created in step 4 to `.env`:

```bash title=".env"
ADMIN_EMAILS=you@example.com
```

Recreate the app container so it reads the change, then sign in and open `/admin`:

```bash title="Terminal"
docker compose up -d app
```

The address becomes an admin the first time it opens `/admin`. `ADMIN_USER_IDS` works the same way with user ids.

## Use Neon or another managed Postgres [#use-neon-or-another-managed-postgres]

You can skip the bundled Postgres and run only the app image. Set `DATABASE_URL` in `.env` to your Neon connection string and leave `DATABASE_HTTP_ENDPOINT` unset.

```bash title="Terminal"
docker build -t qrdx --build-arg NEXT_PUBLIC_APP_URL=https://qr.example.com .
docker run -d --env-file .env -p 3000:3000 qrdx
```

Apply the schema once, and again after each update, with the migrator image:

```bash title="Terminal"
docker build --target migrator -t qrdx-migrate .
docker run --rm -e DATABASE_URL="<your connection string>" qrdx-migrate
```

## Manual setup with Node.js [#manual-setup-with-nodejs]

```bash title="Terminal"
git clone https://github.com/qrdxinc/qrdx.git
cd qrdx
bun install

cp apps/app/.env.example apps/app/.env.local   # then edit it as in step 2

bun run db:push                                # apply the schema
bun run --filter app dev                       # http://localhost:3000
```

For production, build and start the app:

```bash title="Terminal"
bun x turbo build --filter=app
bun run --filter app start
```

`bun run db:push` connects with Neon's driver, so it needs a Neon database. To use the Docker Postgres for local development instead, start it with `docker compose up -d db db-proxy`, apply the schema with `docker compose run --rm migrate`, and set these in `apps/app/.env.local`:

```bash title="apps/app/.env.local"
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/qrdx
DATABASE_HTTP_ENDPOINT=http://localhost:4444/sql
```

## Environment variables [#environment-variables]

[`apps/app/.env.example`](https://github.com/qrdxinc/qrdx/blob/main/apps/app/.env.example) lists every variable with a note on where to get it. The app checks every value when it starts and refuses to start on a missing required value or an invalid one, naming the variable.

### Required [#required]

| Variable | Purpose |
| --- | --- |
| `NEXT_PUBLIC_APP_URL` | Public URL of your instance |
| `DATABASE_URL` | Postgres connection string (set by Compose) |
| `BETTER_AUTH_SECRET` | Signs sessions and cookies |

Add one OAuth provider (GitHub or Google), or Resend for email sign-in codes, so people can sign in.

### Optional services [#optional-services]

Each variable switches on only its own feature. An empty value counts as unset; a value that is set but invalid (a URL that isn't one, a key that is too short) stops the app with the variable's name.

| Service | Variables | Without it |
| --- | --- | --- |
| GitHub sign-in | `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET` | GitHub sign-in is unavailable |
| Google sign-in | `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` | Google sign-in is unavailable |
| Auth base URL | `BETTER_AUTH_URL` | Inferred from each request, with a warning in the logs |
| Admin panel | `ADMIN_EMAILS`, `ADMIN_USER_IDS` | Nobody can open `/admin` |
| Workspace single sign-on | `QRDX_EE_LICENSE`, a key QRdx issues | Without a valid key, single sign-on stays off: no **Sign in with SSO**, no SSO settings, and its sign-in routes don't exist. A connection saved while a key was valid can still be removed: open `/dashboard/<workspace>/settings/sso`, which the menu no longer links to. SSO is in the `ee/` folders under the QRdx commercial license, so production use needs a written agreement with QRdx. See [Single sign-on](https://qrdx.dev/docs/help/teams/single-sign-on) |
| Workspace audit log | `QRDX_EE_LICENSE`, a key QRdx issues | Without a valid key, the audit log stays off: nothing is recorded and there's no **Settings** → **Audit log**. Like single sign-on, it's in the `ee/` folders under the QRdx commercial license. Its rows are kept 365 days; the [scheduled webhook job](#scheduled-jobs) deletes older ones. See [Audit log](https://qrdx.dev/docs/help/teams/audit-log) |
| Client portal and client reports | `QRDX_EE_LICENSE`, a key QRdx issues | Without a valid key, there's no client portal and no **Settings** → **Client portal**, and shared stats pages show no client brand. Clients invited while a key was valid can still be removed: open `/dashboard/<workspace>/settings/clients`, which the menu no longer links to. Stats links already sent on your own domain keep opening. They're in the `ee/` folders under the QRdx commercial license. See [Client portal](https://qrdx.dev/docs/client-portal) |
| White-label pages and custom CSS | `QRDX_EE_LICENSE`, a key QRdx issues | Without a valid key, hosted pages show QRdx's default branding and apply no custom CSS; the editor doesn't offer either. Every page keeps working. In the `ee/` folders under the QRdx commercial license. See [Landing pages](https://qrdx.dev/docs/landing-pages#limits-and-plans) |
| Conversion tracking | `QRDX_EE_LICENSE`, a key QRdx issues | Without a valid key, scans carry no `qrdx_sid`, `POST /api/v1/conversions` and `/conversions.js` answer 404, and the dashboard doesn't offer conversion tracking. Conversions already recorded stay in the data export. In the `ee/` folders under the QRdx commercial license. See [Tracking and conversions](https://qrdx.dev/docs/tracking-and-conversions) |
| AI themes, prompt enhancement and AI QR art (Vercel AI Gateway) | `AI_GATEWAY_API_KEY` | AI requests fail and the AI pages leave the navigation and sitemap. The editor works normally. Create the key in your own Vercel account (AI Gateway, API keys); usage is billed to that account's AI Gateway credits, and your app doesn't have to run on Vercel. The model for each task is set in `apps/app/lib/ai/models.ts` |
| Short-link origin | `NEXT_PUBLIC_SHORT_LINK_BASE_URL` | [Dynamic codes](https://qrdx.dev/docs/dynamic-qr-codes#self-hosting) use `NEXT_PUBLIC_APP_URL` |
| Scan privacy salt | `SCAN_HASH_SALT` | Derived from `BETTER_AUTH_SECRET` |
| File storage (Cloudflare R2) | `R2_ACCOUNT_ID`, `R2_ACCESS_KEY_ID`, `R2_SECRET_ACCESS_KEY`, `R2_BUCKET`, `R2_PUBLIC_BASE_URL` | Uploads are off; pages can still link to files hosted elsewhere. See [Files](https://qrdx.dev/docs/files#set-up-storage-self-hosting) |
| Email (Resend) | `RESEND_API_KEY`, `EMAIL_FROM` | Emails are skipped and logged, so email sign-in codes can't be sent and the sign-in page leaves out the email form; team invites use copyable links. See [Notifications](https://qrdx.dev/docs/notifications#self-hosting) |
| Custom domains on Vercel | `VERCEL_API_TOKEN`, `VERCEL_PROJECT_ID`, `VERCEL_TEAM_ID` | Leave unset off Vercel: domains are then verified with a DNS `TXT` record. See [Custom domains](https://qrdx.dev/docs/custom-domains#self-hosting) |
| One-click DNS setup (Domain Connect) | `DOMAIN_CONNECT_PROVIDER_ID`, `DOMAIN_CONNECT_SERVICE_ID`, `DOMAIN_CONNECT_PRIVATE_KEY` | No **Set up with …** button: people add DNS records themselves. Needs your own Domain Connect template accepted by each DNS provider, and its public key in DNS. See [Custom domains](https://qrdx.dev/docs/custom-domains#self-hosting) |
| Scheduled jobs | `CRON_SECRET` | In production the [weekly digest and webhook retry routes](#scheduled-jobs) answer `401`, so digests aren't sent, failed webhooks aren't retried and audit log rows older than 365 days aren't deleted |
| Link safety (Google Web Risk) | `WEB_RISK_API_KEY` | Destinations are checked by the offline rules only. See [Code controls](https://qrdx.dev/docs/code-controls#safety-checks-on-links) |
| Abuse limits | `SAFETY_YOUNG_ACCOUNT_DAYS`, `SAFETY_YOUNG_ACCOUNT_DYNAMIC_PER_HOUR`, `SAFETY_RECHECK_BATCH` | The defaults in `apps/app/lib/safety/limits.ts` apply (7 days, 30 codes an hour, 500 destinations per recheck) |
| Form spam check (Cloudflare Turnstile) | `NEXT_PUBLIC_TURNSTILE_SITE_KEY`, `TURNSTILE_SECRET_KEY` | Forms rely on the built-in honeypot and rate limits. See [Menus, coupons, events and forms](https://qrdx.dev/docs/forms-and-pages#self-hosting) |
| Payments (Polar) | `POLAR_ACCESS_TOKEN`, `POLAR_WEBHOOK_SECRET`, `NEXT_PUBLIC_QRDX_PRO_MONTHLY_PRODUCT_ID`, `NEXT_PUBLIC_QRDX_PRO_YEARLY_PRODUCT_ID`, `NEXT_PUBLIC_QRDX_BUSINESS_MONTHLY_PRODUCT_ID`, `NEXT_PUBLIC_QRDX_BUSINESS_YEARLY_PRODUCT_ID` | Nothing is sold: upgrading doesn't work (plans without a product id show "Coming soon") and every account is on Free. See [Plans and limits](#plans-and-limits) |
| Euro prices | `NEXT_PUBLIC_QRDX_EUR_PRICES=1`, set only once every product above has a EUR price in Polar | Visitors from the EU and EEA see, and are charged, US$ prices |
| Affiliate program | None: it runs only where QRdx itself runs | Off on a self-hosted copy: no **/affiliates** page, no applications, no **Settings** → **Affiliate program**, and referral links go to the home page |
| Dub short links | `DUB_CLIENT_ID`, `DUB_CLIENT_SECRET`, `DUB_REDIRECT_URI`, `INTEGRATION_ENCRYPTION_KEY` | The Dub integration can't be connected |
| Google Drive | `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, `GOOGLE_DRIVE_REDIRECT_URI`, `INTEGRATION_ENCRYPTION_KEY` | The Google Drive integration can't be connected |
| Bitly, Dropbox, OneDrive, Box, Notion | `BITLY_CLIENT_ID`/`_SECRET`, `DROPBOX_CLIENT_ID`/`_SECRET`, `MICROSOFT_CLIENT_ID`/`_SECRET`, `BOX_CLIENT_ID`/`_SECRET`, `NOTION_CLIENT_ID`/`_SECRET`, `INTEGRATION_ENCRYPTION_KEY` | That integration shows "Not configured" (Bitly still connects with pasted access tokens). Rebrandly and Short.io need no variables. See [Short links and file pickers](https://qrdx.dev/docs/short-links-and-file-pickers#self-hosting) |
| Calendly, Google Sheets, HubSpot, Mailchimp | `CALENDLY_CLIENT_ID`/`_SECRET`, `HUBSPOT_CLIENT_ID`/`_SECRET`, `MAILCHIMP_CLIENT_ID`/`_SECRET`, `INTEGRATION_ENCRYPTION_KEY`; Google Sheets uses `GOOGLE_CLIENT_ID`/`_SECRET` | That integration shows "Not configured". Stripe, Cal.com and Shopify need no variables: people paste their own key |
| YouTube and Spotify pickers | `YOUTUBE_API_KEY`; `SPOTIFY_CLIENT_ID`, `SPOTIFY_CLIENT_SECRET` | Pasting a YouTube or Spotify link works; picking from your channel or your playlists doesn't |
| Slack bot | `SLACK_CLIENT_ID`, `SLACK_CLIENT_SECRET`, `SLACK_SIGNING_SECRET`, plus `INTEGRATION_ENCRYPTION_KEY` in production | No Slack bot: its routes and link page answer 404 and Settings doesn't offer it. Create your own Slack app from [`plugins/slack/manifest.json`](https://github.com/qrdxinc/qrdx/tree/main/plugins/slack) as its README describes. See [Slack bot](https://qrdx.dev/docs/slack-bot#self-hosting) |
| Discord bot | `DISCORD_APPLICATION_ID`, `DISCORD_PUBLIC_KEY` | No Discord bot: its interactions endpoint answers 404 and it's left out of the integrations directory. Register your own Discord app as [`plugins/discord/README.md`](https://github.com/qrdxinc/qrdx/tree/main/plugins/discord) describes. See [Discord bot](https://qrdx.dev/docs/discord-bot#self-hosting) |
| Telegram bot | `TELEGRAM_BOT_TOKEN`, `TELEGRAM_WEBHOOK_SECRET`, `TELEGRAM_BOT_USERNAME` | No Telegram bot: its routes answer 404 and the site doesn't list it. Create your own bot with @BotFather and run `plugins/telegram/scripts/setup.mjs`. See [Telegram bot](https://qrdx.dev/docs/telegram-bot#self-hosting) |
| Rate limiting (Upstash) | `UPSTASH_REDIS_REST_URL`, `UPSTASH_REDIS_REST_TOKEN` (or the Vercel KV names `KV_REST_API_URL`, `KV_REST_API_TOKEN`) | No rate limiting. Recommended in production |
| Analytics (PostHog, after cookie consent) | `NEXT_PUBLIC_POSTHOG_KEY`, `NEXT_PUBLIC_POSTHOG_HOST` | No product analytics |
| Analytics (Umami, cookieless) | `NEXT_PUBLIC_UMAMI_WEBSITE_ID`, `NEXT_PUBLIC_UMAMI_SCRIPT_URL` | No visit counts |
| Feedback widget | `NEXT_PUBLIC_FEATUREBASE_APP_ID` | The widget doesn't load |
| Home page numbers | `QRDX_HOME_NUMBERS=1` | The "QRdx in numbers" section stays off. It's read where the app is built, and the Docker image doesn't pass it to its build |
| Content-Security-Policy switches | `CSP_REPORT_ONLY`, `CSP_HTTPS` | The policy is enforced as is. See [Content-Security-Policy](#content-security-policy) |
| Docs, console and OpenAI directory | `DOCS_ZONE_URL`, `CONSOLE_ORIGIN`, `CONSOLE_ZONE_KEY`, `OPENAI_APPS_CHALLENGE`, `GSC_SERVICE_ACCOUNT_JSON` | Leave unset when self-hosting. They connect qrdx.dev to its own docs site, console and directory listings; without them docs links go to qrdx.dev and the admin pages are served by the app itself |

`INTEGRATION_ENCRYPTION_KEY` must be set in production as soon as you enable an integration, because it encrypts the stored tokens. Generate it with `openssl rand -hex 32`.

**NEXT_PUBLIC_* values are fixed at build time**

`NEXT_PUBLIC_*` values are inlined into the browser bundle when the app is built, so changing one means rebuilding. The Docker build reads `.env` only for six of them, passed as build arguments in `docker-compose.yml`: `NEXT_PUBLIC_APP_URL`, `NEXT_PUBLIC_POSTHOG_KEY`, `NEXT_PUBLIC_POSTHOG_HOST`, `NEXT_PUBLIC_FEATUREBASE_APP_ID` and the two Pro product ids. To set another one in the Docker image (the Business product ids, `NEXT_PUBLIC_QRDX_EUR_PRICES`, `NEXT_PUBLIC_SHORT_LINK_BASE_URL`, the Turnstile site key or the Umami ids), add it to the `app` service's `build.args` in `docker-compose.yml` and as an `ARG` in the Dockerfile's build stage, then run `docker compose up -d --build`. The manual setup reads them all from `apps/app/.env.local`.

### Scheduled jobs [#scheduled-jobs]

Two routes do the recurring work: `/api/cron/webhooks` retries failed webhook deliveries and deletes old audit log rows, and `/api/cron/digest` sends the weekly digest. On Vercel, `apps/app/vercel.json` schedules them. Anywhere else, nothing calls them until you do. Set `CRON_SECRET` and call both from your scheduler with it:

```text title="crontab (times in UTC)"
0 4 * * *  curl -fsS -H "Authorization: Bearer $CRON_SECRET" https://qr.example.com/api/cron/webhooks
0 9 * * 1  curl -fsS -H "Authorization: Bearer $CRON_SECRET" "https://qr.example.com/api/cron/digest?shard=all"
```

Without the header, the routes answer `401` in production. [Notifications](https://qrdx.dev/docs/notifications#self-hosting) explains the digest's `shard` parameter.

## Plans and limits [#plans-and-limits]

Each plan's limits are defined in one file, `apps/app/lib/plans.ts` (`PLAN_LIMITS`). The app and sign-in both read it, so a change there applies everywhere: what each plan can create, who can make more workspaces, how many members a workspace can have, and whether a workspace can require two-step verification. Rebuild and restart after changing it.

Without Polar (`POLAR_ACCESS_TOKEN` unset), nothing is sold and every account is on Free. As shipped, Free gives each person one workspace and no other members. To use teams, raise Free's limits, for example:

```ts title="apps/app/lib/plans.ts"
free: {
  // ...
  teams: true, // people can create more workspaces
  teamMembers: 10, // members per workspace, owner included (UNLIMITED for no cap)
  requireTwoFactor: true, // a workspace can require two-step verification
  // ...
},
```

The `ee/` features work differently: single sign-on, the audit log, the client portal and client reports, white-label pages with custom CSS (without the "Made with QRdx" footer), and conversion tracking. With a valid `QRDX_EE_LICENSE` and `POLAR_ACCESS_TOKEN` unset, every workspace has the ones its key covers (all of them, unless QRdx issued it for fewer), whatever its plan. That applies when `NEXT_PUBLIC_APP_URL` is your own domain. On `localhost`, and on any server where Polar is set up, they follow each plan's limits (`sso`, `auditLog`, `clientReports`, `clientReportsWhiteLabel`, `clientPortal`, `whiteLabel`, `customCss` and `conversions`; as shipped, client reports from Pro and the rest on Business). Production use of any of them still needs a written agreement with QRdx.

## Reverse proxy and HTTPS [#reverse-proxy-and-https]

Put the app behind a reverse proxy such as Caddy, nginx or Traefik that terminates TLS, and don't expose port 3000 to the internet directly. Rate limiting, the security emails and the [audit log](https://qrdx.dev/docs/help/teams/audit-log) read the client IP from `X-Real-IP` first and then from the first `X-Forwarded-For` address (on Vercel, `X-Vercel-Forwarded-For` comes in between), so the proxy must set these headers and the app must only be reachable through it. Have the proxy set `X-Real-IP` to the address it received the connection from. A proxy that only appends to `X-Forwarded-For` lets a client put any address first.

```nginx title="nginx server block (the relevant lines)"
location / {
  proxy_pass http://127.0.0.1:3000;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
}
```

Caddy sets these headers by default. Once HTTPS works, change `NEXT_PUBLIC_APP_URL` and `BETTER_AUTH_URL` to the `https://` URL, update the OAuth callback URLs, and rebuild.

### Content-Security-Policy [#content-security-policy]

Production builds send a Content-Security-Policy on QRdx's own pages: signed-in pages get a fresh script nonce per request, prerendered pages an allowlist of script hosts. Hosted pages (`/p`) get a loose policy, because they run the owner's pixels and embed media from anywhere. If your reverse proxy also sets `Content-Security-Policy`, browsers enforce both, so leave it out there. Set `CSP_REPORT_ONLY=1` to send the policy as report-only while you check a new setup; violations are logged by `/api/csp-report`. Add `CSP_HTTPS=1` when you serve over HTTPS outside Vercel, so browsers upgrade any `http://` resource. Both are read where the app runs and, for the prerendered pages' header, where it is built; the Dockerfile doesn't pass them to the build, so add them as build arguments too if the prerendered pages need them.

## Update QRdx [#update-qrdx]

Back up the database first (see below). Then pull and rebuild. The `migrate` service syncs the schema again before the app starts.

```bash title="Terminal"
git pull
docker compose up -d --build
```

For the manual setup, run `git pull`, `bun install` and `bun run db:push`, then rebuild and restart.

If a schema change would drop data, `drizzle-kit push` asks for confirmation and the `migrate` service waits for an answer it can't get. In that case, run it in a terminal to review and confirm the changes:

```bash title="Terminal"
docker compose run --rm migrate
```

## Back up and restore [#back-up-and-restore]

Everything QRdx stores is in Postgres, except uploaded files, which are in your R2 bucket. Dump the database before every update and on a schedule:

```bash title="Terminal"
docker compose exec db pg_dump -U postgres qrdx > qrdx-backup.sql
```

To restore into an empty database:

```bash title="Terminal"
docker compose exec -T db psql -U postgres qrdx < qrdx-backup.sql
```

With Neon, use its own backups and branching instead.

## What is different from qrdx.dev [#what-is-different-from-qrdxdev]

- **Docs** open on qrdx.dev. Your instance redirects every docs URL there.
- **Payments and plans** need Polar. Without it, every account has the Free limits, and nobody can upgrade. As shipped, that means no webhooks, no custom domains and no custom back-halves, and the dashboard still shows upgrade buttons. The limits themselves are in `apps/app/lib/plans.ts`, which you can change for your instance; see [Plans and limits](#plans-and-limits).
- **The affiliate program, pay-by-invoice requests, non-profit discounts and the enterprise contact form** are QRdx's own sales and run only where QRdx itself runs. A self-hosted copy has none of them.
- **Scan locations:** country, region and city come from Vercel's geo headers. Behind Cloudflare only the country is read (`CF-IPCountry`); elsewhere locations show as unknown, and [area rules](https://qrdx.dev/docs/precise-location#route-scans-by-area) only match scans with a shared location.
- **Custom domains** are verified with a DNS `TXT` record and routed by your reverse proxy, unless you run on Vercel with the Domains API variables set. The **Set up with …** button needs your own Domain Connect template: QRdx's works only for qrdx.dev.
- **Chat bots and integrations** each need an app you register with that service (see the table above).
- **Admin pages** are served by the app itself; qrdx.dev proxies some of them to a separate console.

## Troubleshooting [#troubleshooting]

### "Invalid environment variables" on startup [#invalid-environment-variables-on-startup]

The log names each missing or invalid variable, then says where to set it. A required value is missing, or an optional one is set to something invalid: a URL that isn't a full `http://` or `https://` address, or a secret that is too short. An empty value counts as unset and is fine. Fix the named variables in `.env` and recreate the container with `docker compose up -d app`.

### The sign-in page says sign-in isn't set up [#the-sign-in-page-says-sign-in-isnt-set-up]

None of the ways in can work on your server yet. GitHub and Google each need both their client ID and secret, and email codes need Resend (`RESEND_API_KEY` and `EMAIL_FROM`) with a `NEXT_PUBLIC_APP_URL` that isn't `localhost`. Set at least one, then recreate the container with `docker compose up -d app`. No rebuild is needed: the sign-in page and dialog ask the running server.

### OAuth `redirect_uri` mismatch [#oauth-redirect_uri-mismatch]

The callback URL in your OAuth app must be exactly `<NEXT_PUBLIC_APP_URL>/api/auth/callback/github` or `/api/auth/callback/google`. Set `BETTER_AUTH_URL` to the same base URL as `NEXT_PUBLIC_APP_URL`.

### The app can't reach the database (`fetch failed`) [#the-app-cant-reach-the-database-fetch-failed]

With plain Postgres, `DATABASE_HTTP_ENDPOINT` must point at the running proxy. Check `docker compose ps db-proxy` shows it running.

### `migrate` never finishes [#migrate-never-finishes]

`drizzle-kit push` is waiting for a confirmation. Run `docker compose run --rm migrate` in a terminal and answer it; see [Update QRdx](#update-qrdx).

### A changed `NEXT_PUBLIC_*` value has no effect [#a-changed-next_public_-value-has-no-effect]

Rebuild the image: `docker compose up -d --build`.

### Port 4444 is already in use [#port-4444-is-already-in-use]

Change the `db-proxy` port mapping in `docker-compose.yml`. Only local development on the host uses it.

### "the --mount option requires BuildKit" [#the---mount-option-requires-buildkit]

Your Docker has no BuildKit. Install the `buildx` plugin, or update Docker.

### The build stops with `Killed` or exit code 137 [#the-build-stops-with-killed-or-exit-code-137]

Docker ran out of memory. Give it at least 8 GB (Docker Desktop: **Settings** → **Resources**) and run `docker compose up -d --build` again.

### The build stops with "JavaScript heap out of memory" and "Failed to type check" [#the-build-stops-with-javascript-heap-out-of-memory-and-failed-to-type-check]

Node's heap ran out during the type check in `next build`; giving Docker more memory doesn't help. Current versions skip that check in the image build, the way QRdx's own builds do: CI type-checks every change before a release. Pull the latest code and run `docker compose up -d --build` again. If you need to build an older version, add `NODE_OPTIONS=--max-old-space-size=4096` to the `ENV` line in the Dockerfile's build stage.

### "Email sign-in isn't set up on this site" [#email-sign-in-isnt-set-up-on-this-site]

Email codes aren't sent while `NEXT_PUBLIC_APP_URL` is `localhost`, or when Resend isn't set up, so the sign-in page leaves out the email form. A request for a code answers `400` with `SIGN_IN_CODES_UNAVAILABLE`, and `docker compose logs app` shows `{"event":"auth.email_otp.unavailable"}`. Older versions logged "sign-in code email is off for this deployment" instead. Use GitHub or Google sign-in for a local test.

Still stuck? [Open an issue](https://github.com/qrdxinc/qrdx/issues) with the output of `docker compose logs app`, with secrets removed.

## Related [#related]

- [Files: set up storage](https://qrdx.dev/docs/files#set-up-storage-self-hosting): Cloudflare R2 for uploads, with the CORS policy the bucket needs.
- [Custom domains: self-hosting](https://qrdx.dev/docs/custom-domains#self-hosting): Route customers' domains through your reverse proxy and verify them with a TXT record.
- [Notifications: self-hosting](https://qrdx.dev/docs/notifications#self-hosting): Resend for email and the weekly digest cron job.
- [REST API](https://qrdx.dev/docs/developers/rest-api): Your instance serves the same API under its own URL.
