Skip to content
Josef Ráž edited this page Oct 7, 2024 · 3 revisions

Server installation

Tutorial showing how to install Trek server.

Requirements

  • VPS or just machine with public IP address
  • Docker (with compose) and git installed
  • domain (optional)

Clone repository

$ git clone https://github.com/jsfraz/trek-server.git

Configure environmental variables

Go to the cloned folder and create .env file with following content and modify it as you need:

POSTGRES_USER=trek
POSTGRES_PASSWORD=12345678
POSTGRES_PORT=5432
POSTGRES_DB=trek
ACCESS_TOKEN_SECRET=...your secret text...
ACCESS_TOKEN_LIFESPAN=111600
TRACKER_TOKEN_SECRET=...your secret text...
SUPERUSER_USERNAME=root
SUPERUSER_PASSWORD=12345678
CLIENT_URL=https://your-trek.example.com

Environmental variables table

ENV Example value Description
POSTGRES_USER trek Database user
POSTGRES_PASSWORD 12345678 Database password
POSTGRES_PORT 5432 Database port
POSTGRES_DB trek Database name
ACCESS_TOKEN_SECRET ...your secret text... User access token secret, should be long unique secret text.
ACCESS_TOKEN_LIFESPAN 111600 User access token lifespan in seconds.
TRACKER_TOKEN_SECRET ...your secret text... Tracker access token secret, should be long unique secret text.
SUPERUSER_USERNAME root Trek admin username
SUPERUSER_PASSWORD 12345678 Trek admin password
CLIENT_URL https://your-trek.example.com Trek client URL

Running the Docker compose

This command runs the compose file and creates the container.

$ docker compose up --build -d

You can omit --build if you don't want to build server image again. Used when you modify .env and re-run compose.

Now the server is running on server's http://localhost:8080

Create DNS record (optional)

Create DNS A record for subdomain pointing to your machine's public IP.

Configure Nginx reverse proxy

Create Nginx config file /etc/nginx/conf.d/your-trek-backend.conf with following config:

Replace your-trek-backend.example.com with your machine's public IP or optionally DNS name.

server {
    listen 80;
    server_name your-trek-backend.example.com;

    location / {
        proxy_pass http://127.0.0.1:8080/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Configure HTTPS (optional)

If you have used domain name in the Nginx configuration, you can generate SSL certificate to use SSL.

Install Certbot:

$ sudo apt install certbot python3-certbot-nginx

Automatically configure HTTPS using Let's Encrypt. Replace your-trek-backend.example.com with your DNS name:

$ sudo certbot --nginx -d your-trek-backend.example.com

Success

You have installed Trek serever!