Skip to main content

Environment Variables

Configuration reference for self-hosting LinkForty Core. Set these in your .env file (or your platform's environment configuration). Only DATABASE_URL is strictly required; everything else has a sensible default or is optional.

Database​

VariableRequiredDefaultDescription
DATABASE_URLYes—PostgreSQL connection string: postgresql://user:password@host:5432/dbname.
POSTGRES_DBNo—Database name (Docker Compose convenience; used to compose DATABASE_URL).
POSTGRES_USERNo—Database user (Docker Compose).
POSTGRES_PASSWORDNo—Database password (Docker Compose).
POSTGRES_PORTNo5432Database port (Docker Compose).

Caching (optional)​

VariableRequiredDefaultDescription
REDIS_URLNo—Redis connection string for link caching (redis://host:6379). Omit to disable — Core falls back to direct database queries.
REDIS_PORTNo6379Redis port (Docker Compose).

Server​

VariableRequiredDefaultDescription
NODE_ENVNodevelopmentSet to production in production (enables SSL behavior and hides internal error details).
PORTNo3000Port the server listens on.
HOSTNo0.0.0.0Bind address.
LINKFORTY_CONFIGNolinkforty.config.json in the working directoryPath to Core's configuration file.
CORS_ORIGINNo*Allowed CORS origin(s). Set to your frontend domain in production.
SHORTLINK_DOMAINNothe request's hostBase URL encoded in QR codes, including the scheme (https://go.yourdomain.com).

Attribution behind a proxy or CDN​

VariableRequiredDefaultDescription
TRUST_PROXYNounsetNumber of reverse proxies between the visitor and Core (1 for a single nginx). Core then reads the visitor's IP from X-Forwarded-For. true trusts every hop. Read by the Docker image and the example server; with the npm package, pass trustProxy to createServer().
TRUSTED_CLIENT_IP_HEADERNounsetName of a header carrying the authoritative client IP, e.g. cf-connecting-ip. When set, Core reads that header and ignores X-Forwarded-For.

When neither is set, Core uses the IP of the connection. Behind any reverse proxy or CDN (nginx, Caddy, a load balancer, a Kubernetes ingress, Cloudflare), that is the proxy's address, not the visitor's: 127.0.0.1 for an nginx on the same host, an edge address for a CDN.

This breaks deferred deep linking outright. Core matches an install to the click that led to it by comparing device signals, and the IP is the signal it requires: without an IP match no click can reach the confidence threshold. Core also refuses to match on loopback and private addresses, since they cannot identify a device. So behind an unconfigured proxy every install is organic. Geo-targeting and the location columns in analytics fail the same way.

Pick the setting that matches what is in front of Core:

# A reverse proxy that sets X-Forwarded-For: nginx, Caddy, HAProxy, a load
# balancer, an ingress controller. One proxy → 1; a load balancer in front of
# nginx → 2.
TRUST_PROXY=1

# A CDN with its own client-IP header. Core reads that header instead.
TRUSTED_CLIENT_IP_HEADER=cf-connecting-ip # Cloudflare
TRUSTED_CLIENT_IP_HEADER=true-client-ip # Akamai and some other CDNs

TRUST_PROXY is the right choice for the nginx setup in the self-hosting guide. Comma-separated header values are handled (Core takes the first entry), and IPv6-mapped IPv4 addresses are normalized.

Only enable behind a trusted proxy

Both settings trust what the proxy says about the visitor. Set them only when Core is reachable exclusively through that proxy: bind Core to 127.0.0.1 or firewall its port. A client that can reach Core directly could otherwise forge its IP. When no proxy is in front of Core, leave both unset.

To verify, click a test link from a phone and check the click in link analytics: it should carry the visitor's country and city, not the server's.

LinkForty Cloud

On LinkForty Cloud this is already configured. You only need these variables for a self-hosted deployment behind a proxy or CDN.

Bot detection (optional)​

VariableRequiredDefaultDescription
ASN_DB_PATHNo—Path to an IP-to-ASN database in MMDB format. Setting it turns on experimental scanner detection. Read by the Docker image and the example server; with the npm package, pass botDetection.asnDatabasePath.
TRUST_EDGE_BOT_HEADERNounsetSet to true to accept the x-lf-bot header (1 or true) as a signal that a click came from a bot. Only enable it behind a proxy that sets this header and strips copies sent by clients; otherwise a client could mark its own clicks.

These power the .well-known files Core serves for iOS Universal Links and Android App Links. See iOS Universal Links and Android App Links for setup.

VariableRequiredDefaultDescription
IOS_TEAM_IDNo—Apple Developer Team ID. Required to serve apple-app-site-association.
IOS_BUNDLE_IDNo—Your iOS app bundle identifier (e.g. com.yourcompany.yourapp).
ANDROID_PACKAGE_NAMENo—Your Android package name. Required to serve assetlinks.json.
ANDROID_SHA256_FINGERPRINTSNo—Comma-separated SHA-256 signing-certificate fingerprints.

When the iOS pair is unset, GET /.well-known/apple-app-site-association returns a 404 with a configuration message. The same applies to the Android pair and assetlinks.json.

Example .env​

# Database
DATABASE_URL=postgresql://linkforty:your-strong-password@localhost:5432/linkforty

# Caching (optional)
REDIS_URL=redis://localhost:6379

# Server
NODE_ENV=production
PORT=3000
HOST=0.0.0.0
CORS_ORIGIN=https://yourdomain.com
SHORTLINK_DOMAIN=https://go.yourdomain.com

# Behind a reverse proxy (nginx, a load balancer): the number of proxies in
# front of Core, so the visitor's IP is read from X-Forwarded-For
TRUST_PROXY=1

# Behind Cloudflare instead: read its client-IP header
# TRUSTED_CLIENT_IP_HEADER=cf-connecting-ip

# iOS Universal Links
IOS_TEAM_ID=ABC123XYZ
IOS_BUNDLE_ID=com.yourcompany.yourapp

# Android App Links
ANDROID_PACKAGE_NAME=com.yourcompany.yourapp
ANDROID_SHA256_FINGERPRINTS=AA:BB:CC:DD:...