Skip to content
totaljsPublic

About

Total.js Proxy Server with full SSL support

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

Total.js Proxy logo

Total.js Proxy

Total.js Platform Automatic HTTPS with Let's Encrypt Linux amd64 and arm64 Node.js 24

Publish your Docker apps with a domain and automatic HTTPS.

Total.js Proxy is a self-hosted reverse proxy for Total.js apps and other HTTP services. Point a domain at your server and tell Proxy which container to reach. Proxy routes requests by hostname, forwards WebSockets, and issues and renews Let's Encrypt certificates, including wildcards. Everything is set with files that Proxy watches: one JSON file for each site, or none at all when the containers publish themselves.

Run it on a server

You need a Linux server with Docker and the ports 80 and 443 open. Proxy and your apps meet on one Docker network, named proxy.

With the install script

Go to the folder where Proxy should live and run:

curl -fsSL https://raw.githubusercontent.com/totaljs/proxy/main/install.sh -o install.sh
bash install.sh

The script makes the Docker network proxy and a folder proxy in the current folder with compose.yaml, .env, data and logs, then starts Proxy. It asks for sudo once, to give data and logs to the user of the container. Run it again to update to the newest image: a compose.yaml that is already there is kept. PROXY_DIR, PROXY_IMAGE and PROXY_NETWORK change the folder, the image and the network.

Then go to Publish an app.

By hand

1. Create the network and a folder for Proxy

docker network create proxy
mkdir -p /srv/proxy/data /srv/proxy/logs
cd /srv/proxy

2. Save this as /srv/proxy/compose.yaml

services:
  proxy:
    image: totalplatform/proxy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./data:/proxy/data
      - ./logs:/proxy/logs
      - /var/run/docker.sock:/var/run/docker.sock:ro
    group_add:
      - "${DOCKER_GID}"
    networks: [proxy]

networks:
  proxy:
    external: true

3. Let the container write its folders and read the Docker socket, then start it

Proxy runs as the user node (UID 1000), not as root.

sudo chown 1000:1000 data logs
echo "DOCKER_GID=$(stat -c %g /var/run/docker.sock)" > .env
docker compose up -d

Proxy now answers on the server. A domain that has no site yet gets a page that says so.

Publish an app

Point the DNS of your domain to the server. In the Compose file of the app, say which domain it serves and on which port it listens, and put it on the proxy network:

services:
  app:
    image: totalplatform/run:npm
    restart: unless-stopped
    volumes:
      - ./app:/www
    environment:
      PROXY_HOST: "https://example.com,https://www.example.com"
      PROXY_PORT: "8000"
    networks: [proxy]

networks:
  proxy:
    external: true

Start the app with docker compose up -d. Proxy sees the container, writes data/sites/example.com.json, gets a Let's Encrypt certificate for the names written with https:// and serves the app. When the container stops, the site goes with it. The app publishes no ports.

For an app that is not a container on this network, write the file yourself. Proxy applies it within a few seconds, without a restart:

/srv/proxy/data/sites/example.com.json

{
  "hosts": ["https://example.com", "https://www.example.com"],
  "target": "10.0.0.5:8000"
}

Check that it works

docker compose logs proxy
cat logs/error.log

logs/error.log names anything that was not applied and why: a site file with a mistake, a certificate that could not be issued, an app that does not answer. Each site has its own logs/<site>.log.

What is where

Path What it holds
compose.yaml, .env How the container of Proxy is started.
data/config.json The settings of Proxy. Optional: without it the defaults apply.
data/sites/ One JSON file for each site.
data/certs/ The certificates of Let's Encrypt, and your own as <name>.crt + <name>.key.
data/stats/ The request counters of each site.
logs/ One log for each site and error.log.

Back up data: it has the private keys. Every file is watched, so there is no command to check or reload anything.

Mounting the Docker socket lets Proxy see which containers publish themselves, and whoever has the socket controls Docker on that server. Docker discovery describes how to run without it.

Run it without Docker

Proxy is a Node.js program without dependencies. With Node.js 22 or newer, from a checkout of this repository:

node index.js data

data is the folder with config.json and sites/. Proxy makes it, and logs next to it, when they are not there.

  • Ports 80 and 443. A normal user cannot open them on Linux. Run Proxy as root, or let Node open them with sudo setcap 'cap_net_bind_service=+ep' "$(command -v node)", or choose other ports in data/config.json: { "http": 8080, "https": 8443 }.

  • Keeping it running. The command stays in the foreground. On a server, run it under systemd or another process manager, so it starts again after a failure or a reboot:

    [Unit]
    Description=Total.js Proxy
    After=network-online.target
    
    [Service]
    WorkingDirectory=/srv/proxy
    ExecStart=/usr/bin/node /srv/proxy/index.js data
    Restart=always
    User=proxy
    AmbientCapabilities=CAP_NET_BIND_SERVICE
    
    [Install]
    WantedBy=multi-user.target
  • Sites. Write the files of data/sites yourself; a target can be any address, such as 127.0.0.1:8000 for an app on the same machine.

  • Docker discovery still works when the user of Proxy may read /var/run/docker.sock, on Linux, where the addresses of the containers are reachable from the host. Set "docker": "" in data/config.json to turn it off.

Ctrl+C or SIGTERM stops Proxy; it writes its logs and counters first.

Build from source

docker build -t totalplatform/proxy .

Documentation

About

Total.js Proxy Server with full SSL support

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages