Skip to content

Commit 6bb9b73

Browse files
ldanilekConvex, Inc.
authored andcommitted
[self-hosted] docs for custom router (#34859)
add documentation for how to run the docker setup on a server. There are all sorts of ways you can do this, but some tips are general, like explaining which URLs to configure via env vars. Also I noticed that BASE_URL is somewhat confusing. it might make sense to configure the PORT, because you want to avoid port conflicts on your host machine. However, if you're overriding the BASE_URL, then you're probably hosting the site somewhere non-local, which means the port should also change and you should set all of the env var together. So remove BASE_URL GitOrigin-RevId: 43ddab886919aef289a2171e0f1e160de5445b13
1 parent 7a0b0eb commit 6bb9b73

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

self-hosted/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,70 @@ You can run the Convex backend on a hosting provider of your choice. We include
170170
[Fly.io](https://fly.io/). See our dedicated [Fly instructions](./fly/README.md)
171171
to get started.
172172

173+
## Backend hosting on your own infrastructure
174+
175+
It's possible to run Convex on your own servers, with your own routing.
176+
177+
Download the
178+
[`docker-compose.yml` file](https://github.com/get-convex/convex-backend/tree/main/self-hosted/docker/docker-compose.yml)
179+
onto the server you want to run Convex on.
180+
181+
```sh
182+
curl -O https://raw.githubusercontent.com/get-convex/convex-backend/main/self-hosted/docker/docker-compose.yml
183+
```
184+
185+
Your Convex backend will be running on this server at port 3210, with HTTP
186+
actions exposed at port 3211, and the dashboard running on port 6791.
187+
188+
Set up routing to forward requests from your domain to these ports. For example:
189+
190+
- `https://api.my-domain.com` forwards to `http://localhost:3210`
191+
- `https://my-domain.com` forwards to `http://localhost:3211`
192+
- `https://dashboard.my-domain.com` forwards to `http://localhost:6791`
193+
194+
In a `.env` file beside the `docker-compose.yml` file, set the following
195+
environment variables:
196+
197+
```sh
198+
# URL of the Convex API as accessed by the client/frontend.
199+
CONVEX_CLOUD_ORIGIN='https://api.my-domain.com'
200+
# URL of Convex HTTP actions as accessed by the client/frontend.
201+
CONVEX_SITE_ORIGIN='https://my-domain.com'
202+
# URL of the Convex API as accessed by the dashboard (browser).
203+
NEXT_PUBLIC_DEPLOYMENT_URL='https://api.my-domain.com'
204+
```
205+
206+
On the server, start the backend with:
207+
208+
```sh
209+
docker compose up
210+
```
211+
212+
Get an admin key with:
213+
214+
```sh
215+
docker compose exec backend ./generate_admin_key.sh
216+
```
217+
218+
Go to the dashboard at `https://dashboard.my-domain.com` and use the admin key
219+
to authenticate.
220+
221+
In your Convex project (on your local machine, probably not on the hosting
222+
server), add the url and admin key to a `.env.local` file (which should not be
223+
committed to source control):
224+
225+
```sh
226+
CONVEX_SELF_HOSTED_URL='https://api.my-domain.com'
227+
CONVEX_SELF_HOSTED_ADMIN_KEY='<your admin key>'
228+
```
229+
230+
Now you can run commands in your Convex project, to push code, run queries,
231+
import data, etc.
232+
233+
```sh
234+
npx convex dev
235+
```
236+
173237
## Running the database on Postgres or MySQL
174238

175239
The Convex backend is designed to work well with SQLite, Postgres, or MySQL. If

self-hosted/docker/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ services:
1111
- INSTANCE_SECRET=${INSTANCE_SECRET:-}
1212
- CONVEX_RELEASE_VERSION_DEV=${CONVEX_RELEASE_VERSION_DEV:-}
1313
- ACTIONS_USER_TIMEOUT_SECS=${ACTIONS_USER_TIMEOUT_SECS:-}
14-
- CONVEX_CLOUD_ORIGIN=${URL_BASE:-http://127.0.0.1}:${PORT:-3210}
15-
- CONVEX_SITE_ORIGIN=${URL_BASE:-http://127.0.0.1}:${SITE_PROXY_PORT:-3211}
14+
- CONVEX_CLOUD_ORIGIN=http://127.0.0.1:${PORT:-3210}
15+
- CONVEX_SITE_ORIGIN=http://127.0.0.1:${SITE_PROXY_PORT:-3211}
1616
- DATABASE_URL=${DATABASE_URL:-}
1717
- DISABLE_BEACON=${DISABLE_BEACON:-}
1818
- REDACT_LOGS_TO_CLIENT=${REDACT_LOGS_TO_CLIENT:-}

0 commit comments

Comments
 (0)