Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Selfhosted v3.3.0 documentation

Blue Mouse02f9442e055f
diff --git a/docs/selfhosting/configuring.md b/docs/selfhosting/configuring.md
index 3d726b69c..0517d8ce6 100644
--- a/docs/selfhosting/configuring.md
+++ b/docs/selfhosting/configuring.md
@@ -9,23 +9,20 @@ The easiest way to get started with Swetrix is by [using our cloud service](http
The following environment variables are available for configuration:
-## Frontend (swetrix-fe)
+## Frontend (swetrix image)
| Variable | Default | Description |
| --- | --- | --- |
-| `API_URL` | `http://localhost:8080/` | URL of the backend API |
+| `API_URL` | `http://localhost:8080/` | URL of the self-hosted Swetrix API instance. Swetrix frontend will use this variable to connect to the API, so make sure it's correct. |
-## API
+## API (swetrix-api image)
| Variable | Default | Description |
| --- | --- | --- |
-| `EMAIL` | `[email protected]` | Email address to use for access to dashboard |
-| `PASSWORD` | `12345678` | Password to use for access to dashboard |
-| `JWT_ACCESS_TOKEN_SECRET` | `jwt-access-token-secret` | Secret for JWT access tokens |
-| `JWT_REFRESH_TOKEN_SECRET` | `jwt-refresh-token-secret` | Secret for JWT refresh tokens |
-| `REDIS_HOST` | `redis` | Redis host |
-| `CLICKHOUSE_HOST` | `http://clickhouse` | ClickHouse host |
-| `API_ORIGINS` | | A list of allowed origins (for the `Access-Control-Allow-Origin` header) |
+| `EMAIL` | Required | Email address to use for access to dashboard |
+| `PASSWORD` | Required | Password to use for access to dashboard |
+| `JWT_ACCESS_TOKEN_SECRET` | _auto-generated by `configure.sh`_ | Secret for JWT access tokens |
+| `JWT_REFRESH_TOKEN_SECRET` | _auto-generated by `configure.sh`_ | Secret for JWT refresh tokens |
| `API_KEY` | | An optional API key for accessing your stats via the API directly. If not set - direct API access is disabled. |
-| `CLOUDFLARE_PROXY_ENABLED` | `false` | If set to `true` - Swetrix will get geolocation and IP address information from `cf-connecting-ip` and `cf-ipcountry` headers provided by Cloudflare. |
+| `CLOUDFLARE_PROXY_ENABLED` | `false` | If set to `true` - Swetrix will get IP address information from `cf-connecting-ip` header provided by Cloudflare. |
## Redis
| Variable | Default | Description |
diff --git a/docs/selfhosting/how-to.md b/docs/selfhosting/how-to.md
index 16a0fb66e..0a2d4c2dc 100644
--- a/docs/selfhosting/how-to.md
+++ b/docs/selfhosting/how-to.md
@@ -13,69 +13,57 @@ The easiest way to get started with Swetrix is by [using our cloud service](http
To self-host Swetrix you need to have the following:
- A server with Docker installed
- Support for the x86_64 or arm64 CPU architecture on your server
+- At least 2GB of RAM is recommended for the best performance
Most of the cloud providers offer Docker pre-installed on their servers, but in case it's missing, you can install it manually by following the [official Docker installation guide](https://docs.docker.com/get-docker/).
-We've tested self-hosting Swetrix using [Hetzner Cloud](https://hetzner.cloud/?ref=xIW4H6LVD01I) (affiliate link), but any other cloud provider should work just fine.
+We've tested self-hosting Swetrix using [Hetzner Cloud](https://hetzner.cloud), but any other cloud provider should work just fine.
## Installation
### 1. Install the self-hosting repository
+
To self-host Swetrix, download the [self-hosting repository](https://github.com/swetrix/selfhosting) from GitHub.
```bash
git clone https://github.com/swetrix/selfhosting
cd selfhosting
```
-That repository contains a `docker-compose.yml` file with all the necessary configuration to run Swetrix, you'll need to configure it later.
+That repository contains a `compose.yaml` file with all the necessary configuration to run Swetrix, you'll need to configure it later.
-The repository also contains various configuration files to ease the setup process (for example, `nginx` config files).
+The repository also contains various configuration files to ease the setup process (for example, `nginx` or `clickhouse` config files).
### 2. Configure the environment variables
-Swetrix uses environment variables to configure itself. You can find the list of all available environment variables in the [configuration section](/selfhosting/configuring).
-Most of the environment variables are already set by default, but you need to set the following variables:
-- `EMAIL` - email address user will use to log in to the dashboard
-- `PASSWORD` - password user will use to log in to the dashboard
-- `JWT_ACCESS_TOKEN_SECRET` - secret for JWT access tokens, basically a random string of 60 characters.
-- `JWT_REFRESH_TOKEN_SECRET` - secret for JWT refresh tokens, also a random 60 chars string, but this one should be different from the access token secret.
-- `API_URL` - URL (or an IP address) of the machine you're hosting Swetrix on.
+That repository contains a `configure.sh` script that will help you set up the environment variables. It will ask you to enter variables like email and password, and autogenerate some other necessary variables as well.
+
+The script will save the environment variables to a `.env` file in the repository directory. You can later change them manually if needed.
+
+```bash
+./configure.sh
+```
### 3. Run the container
-Before running the following command, make sure that you have Docker installed on your server. You may refer to the [Digital Ocean docker installation guide](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04) for more information.
-Once you've set up the server, you're ready to start up the server:
+Once all the environment variables are set, you can start the containers by running the following command:
```bash
docker compose up -d
```
After you run this command, the following containers will be started:
-- `swetrix-api` - the main API server running on port 8080 by default
-- `swetrix-fe` - the frontend server running on port 80 by default
+- `swetrix-api` - the main API server running on port `8080` by default
+- `swetrix-fe` - the frontend server running on port `80` by default
- Redis server for caching
-- Clickhouse server for analytics data and transactional stuff
+- Clickhouse server for analytics and transactional data
After starting the container you can access the dashboard at `http://{host}:80`.
## Updating
-To update Swetrix to the latest version you have to pull Swetrix images from the Docker Hub and restart the container.
-
-First, pull the Swetrix API image:
-```bash
-docker pull swetrix/swetrix-api
-```
-Next, pull the Swetrix frontend image:
-```bash
-docker pull swetrix/swetrix-fe
-```
-
-And then restart the container:
-```bash
-docker compose restart
-```
+To update Swetrix to the latest version, please refer to the changelog on our [GitHub repository](https://github.com/swetrix/swetrix). Usually, Swetrix releases come with database migrations that you'll need to apply manually. So make sure to backup your database before updating and follow the changelog instructions carefully.
## Reverse proxy
-It's best to make sure your reverse proxy is set up to pass the request IP address as the `x-real-ip` header, otherwise it may cause the problems related to API route rate limiting and analytics sessions. If the `x-real-ip` header is undefined, Swetrix will use `x-forwarded-for` as a backup.
-If you are using Cloudflare as a proxy for your self-hosted Swetrix instance, you can set the `CLOUDFLARE_PROXY_ENABLED` environment variable to `true`. This will allow the Swetrix API to retrieve geolocation and IP address information from the headers provided by Cloudflare (`cf-ipcountry` and `cf-connecting-ip`).
+If you use reverse proxy like Nginx, please set it up to pass the request IP address as the `x-real-ip` header, otherwise it may cause the problems related to API route rate limiting and analytics sessions. If the `x-real-ip` header is undefined, Swetrix will use `x-forwarded-for` or the request IP address as a backup.
+
+If you are using Cloudflare as a proxy for your self-hosted Swetrix instance, you can set the `CLOUDFLARE_PROXY_ENABLED` environment variable to `true`. This will force Swetrix to check the `cf-connecting-ip` header for the IP address.