3. Install Hexcore on a server (Ubuntu, Debian, RHEL family)

3. Install Hexcore on a server (Ubuntu, Debian, RHEL family)

Goal: Hexcore runs as a service, restarts itself when the server reboots, and is reached at https://<domain> with valid TLS (needed for multi-machine heads and Trust Center). Finish 1. Prepare your machine on the server first.

3.1 Overview

  • Hexcore does not handle TLS itself: the reverse proxy takes HTTPS on port 443, forwards to port 4000, and must forward WebSocket upgrades (the node console, the SDK client, and the multi-machine head tunnels).
  • Multi-machine heads in relay mode (the default) go through this same domain, so no extra ports are needed beyond 80 and 443.

3.2 Prepare the server

Run Hexcore as a regular user with sudo, not root (the node keys live in that user's ~/.hexcore). Create a dedicated user if you want one:

bash
sudo adduser hexcore          # Debian/Ubuntu; RHEL family: sudo useradd -m hexcore && sudo passwd hexcore
sudo usermod -aG docker,sudo hexcore   # RHEL family uses the wheel group instead of sudo
su - hexcore

Then install nvm, Node.js and Hexcore as this user, following §1.3–§1.5. Enable time sync: sudo timedatectl set-ntp true.

3.3 First-time setup from the terminal

A server usually has no browser, so use hexcore init instead of the web setup link:

bash
hexcore init
  • Network: a provider joining the Trust Center pilot picks preprod. Chain backend: cardano-node if you have a synced node, otherwise blockfrost.
  • Admin: if you leave the password empty, Hexcore prints a generated password once on first start (read it with hexcore logs); change it with hexcore password.

Check:

bash
hexcore config     # every value and the configuration layer that decided it
hexcore doctor

3.4 Run Hexcore as a service (systemd)

bash
HOST=127.0.0.1 hexcore service install
  • HOST=127.0.0.1 lets only the reverse proxy on the same machine reach port 4000 (the default is 0.0.0.0).
  • Run it without sudo: Hexcore prepares the unit file and prints the commands that need root, run exactly those, usually:
    bash
    sudo cp ~/.hexcore/hexcore.service /etc/systemd/system/hexcore.service
    sudo systemctl daemon-reload
    sudo systemctl enable --now hexcore
    
  • The service uses the exact node binary present at install time: if you change the Node.js version, reinstall Hexcore and rerun the command above.

Check:

bash
hexcore status                 # whether it is running, version, URL
hexcore logs -f                # follow the log (journalctl under systemd)
curl -s http://127.0.0.1:4000/health
TaskCommand
Stop Hexcore (heads keep running)hexcore stop (systemd does not restart it)
Start again after stoppingsudo systemctl start hexcore
Remove the service (keeps config, keys, heads)hexcore service uninstall, then run the sudo commands it prints

No systemd: hexcore start --detach (does not restart after a reboot).

3.5 Domain and DNS

  1. Pick a subdomain, for example hexcore.example.com.
  2. Create an A record pointing to the server's public IPv4 (add an AAAA record if it has IPv6 and the proxy listens on IPv6).
  3. Wait until it resolves to the right IP:
    bash
    dig +short hexcore.example.com
    

Cloudflare: keep the record DNS only (grey cloud), as proxy mode (orange cloud) has not been measured against multi-machine head tunnels (#26).

3.6 Firewall

Open only SSH, 80 (Let's Encrypt validation, redirect to HTTPS) and 443, and do not open port 4000.

Ubuntu, Debian (ufw): allow SSH before enabling ufw, or you lock yourself out of the server:

bash
sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw enable
sudo ufw status

RHEL family (firewalld):

bash
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload

Two things to know about Docker and firewalls:

  • Ports published by Docker bypass ufw and firewalld. The node API is published only on 127.0.0.1, so it is safe, but P2P ports (single-machine heads, multi-machine heads in direct mode) are published on 0.0.0.0, reachable from the Internet even when ufw blocks them. To block them for certain, use your cloud provider's security group.
  • ufw blocks traffic from containers to the host by default, and relay heads need that path: the Start button stops and prints the exact command to run, for example:
    bash
    sudo ufw allow from 10.0.30.0/24 to 10.0.0.1 port 47000:56999 proto tcp
    

    Run it, then click Start again.

Caddy requests and renews Let's Encrypt certificates itself and proxies WebSocket with no extra configuration. Install (per caddyserver.com/docs/install):

bash
# Ubuntu, Debian
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update && sudo apt install -y caddy

# Rocky, AlmaLinux, CentOS Stream, RHEL
sudo dnf install -y 'dnf-command(copr)'
sudo dnf copr enable -y @caddy/caddy
sudo dnf install -y caddy
sudo systemctl enable --now caddy

Write /etc/caddy/Caddyfile (replace the domain):

hexcore.example.com {
    reverse_proxy 127.0.0.1:4000
}

Apply:

bash
sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl reload caddy
journalctl -u caddy -f      # watch the certificate request

Caddy can only get a certificate once DNS is correct and ports 80 and 443 are open.

3.8 Reverse proxy, option 2: nginx + certbot

Install:

bash
# Ubuntu, Debian
sudo apt install -y nginx certbot python3-certbot-nginx

# Rocky, AlmaLinux, CentOS Stream, RHEL (certbot comes from EPEL)
sudo dnf install -y epel-release
sudo dnf install -y nginx certbot python3-certbot-nginx
sudo systemctl enable --now nginx

Write /etc/nginx/conf.d/hexcore.conf (replace the domain):

nginx
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 80;
    server_name hexcore.example.com;

    location / {
        proxy_pass http://127.0.0.1:4000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        # Console and tunnels can stay open for hours; the 60-second default would cut them
        proxy_read_timeout 1h;
        proxy_send_timeout 1h;
    }
}

If nginx reports duplicate "map" variable "$connection_upgrade", delete the map block above. Then request the certificate (certbot adds listen 443 ssl and the HTTPS redirect itself):

bash
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d hexcore.example.com

SELinux on the RHEL family blocks nginx from connecting to 127.0.0.1:4000: 502 Bad Gateway, and the log has connect() to 127.0.0.1:4000 failed (13: Permission denied). Allow it with:

bash
sudo setsebool -P httpd_can_network_connect 1

Keep tokens out of the access log. A token in the query string (?X-Api-Key=hxn_…) is written to nginx's access log. To avoid that, log the head routes without the query (the browser console is not affected, since it uses a single-use 30-second ticket):

nginx
# in the http block (for example at the top of hexcore.conf)
log_format hexcore '$remote_addr [$time_local] "$request_method $uri" $status';

# in the server block, add a separate location with the same proxy_* lines as location /
location /api/heads/ {
    access_log /var/log/nginx/access.log hexcore;
    proxy_pass http://127.0.0.1:4000;
    # … the same proxy_* lines as location / above
}

3.9 Set the Public URL and verify

Sign in at https://hexcore.example.com, go to Settings → Public URL → Use page's address → save (origin only, no path). Other Hexcores reach this machine at that address; without it, relay heads and invitations do not work and Trust Center cannot verify your domain.

Check:

bash
curl -s https://hexcore.example.com/health
  • It returns JSON with the Hexcore and Docker status: the proxy works.
  • The Console of a running node connects through the domain: WebSocket passes through.
  • After connecting Trust Center (part 4), https://hexcore.example.com/.well-known/hexcore/trust-center.json returns the connector's public key (before that, a 404 is normal).

3.10 Maintenance

  • Update: hexcore update. The new version starts alongside the old one, the old one drains open connections (up to 2 minutes), and it rolls back automatically if the new version is unstable in the first minute. The CLI may stay silent during the 60-second watch: it is not hung.
  • Back up ~/.hexcore: it holds every node's keys (including the Cardano keys of funded addresses), the Trust Center connector key and the database. Stop Hexcore before copying so the SQLite copy is consistent (heads keep running):
    bash
    hexcore stop
    tar czf hexcore-backup-$(date +%F).tgz -C ~ .hexcore
    sudo systemctl start hexcore
    

    Store the copy off the server and restrict who can read it: whoever has this file has the node keys.
  • Check regularly: hexcore doctor, especially after changing Docker or the firewall; doctor and Settings warn if a node API is published publicly (NODE_PORT_BIND other than 127.0.0.1).