Text may contain bad spelling, incorrect expressions, verbal turns, sentence constructions, etc.
If the VPS is new and there is no Docker:
apt update && apt upgrade -y
apt install -y curl wget sudo git
curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh ./get-docker.sh
Installation via Script
This is an automatic script for installing and configuring the panel domain, as well as other domains (if needed) and SSL for them. But the NGINX config will be fully configured only for the panel.
git clone https://github.com/nozsh/home-server-vps-ztnet-init ztnet && cd ztnet && bash init/init.sh
Next, create a network in the admin panel. Connect to the network on the home server following the instructions. And on the VPS run:
NET_ID="XYZ"; docker exec ztnet sh -c "cd /var/lib/zerotier-one && mkdir networks.d && cd networks.d && touch $NET_ID.conf"
Where XYZ is the network ID.
If you added other domains besides the panel, you need to edit the NGINX configs – change proxy_pass.
You can skip adding additional domains right away. Later just use the script. Where <ZeroTier_IP> is the home server IP in the ZeroTier network, APP_PORT is the port on which the service runs on the home server.
docker compose down && docker compose up -d && docker compose logs -f
And if the home server loses connect:
sudo systemctl restart zerotier-one
Manually
mkdir ztnet && cd ztnet && wget -O docker-compose.yml https://raw.githubusercontent.com/sinamics/ztnet/main/docker-compose.yml
nano docker-compose.yml
Change everything as you need according to the documentation.
Reverse proxy (NGINX)
nano docker-compose.yml
It should be like this:
| |
Example of complete docker-compose.yml
| |
NGINX configs
mkdir -p nginx/conf.d
nano nginx/conf.d/panel-ztnet.domain.org.conf
Config for panel
| |
nano nginx/conf.d/your-app.domain.org.conf
Config for some services
| |
Change where highlighted. Where <ZeroTier_IP> is the home server IP in the ZeroTier network, APP_PORT is the port on which the service runs on the home server.
SSL
SSL can be obtained through the Docker too, but it will be easier through the host.
apt install certbot
certbot certonly --standalone --non-interactive --agree-tos --email [email protected] -d ztnet-panel.domain.org
ls /etc/letsencrypt/live/
Start
docker compose up -d && docker compose logs -f
In the admin panel, create a network. Connect to the network on the home server following the instructions. Next, you need to add the VPS running ZTNet to the network with the home server:
docker exec -it ztnet sh
cd /var/lib/zerotier-one
mkdir networks.d
cd networks.d
touch <network>.conf
Where <network> is the network ID.
exit
docker compose down && docker compose up -d && docker compose logs -f
And if the home server loses connect:
sudo systemctl restart zerotier-one
Add/Configure Services (NGINX)
To add a new service, copy the existing NGINX configuration, and change the domain and proxy_pass. And request an SSL certificate.
docker compose down && docker compose up -d && docker compose logs -f
Or if you used the automatic configuration script (or just download this script separately), from the directory where docker-compose.yml is located, run:
bash init/add_new.sh
The script will stop the Docker containers, create the NGINX config, request SSL and start the containers. If there were no errors – no manual actions are needed.
Useful commands
Docker
You can check that the connection reaches your home server through the NGINX container with the command:
docker exec nginx wget -O- http://<ZeroTier_IP>:APP_PORT --timeout=5
If something didn’t start, and/or doesn’t work properly after:
docker compose restart && docker compose logs -f
Run:
docker compose down && docker compose up -d && docker compose logs -f
ZeroTier
sudo zerotier-cli join <network>
sudo zerotier-cli leave <network>
sudo zerotier-cli listnetworks
Scripts
VPS
“certbot_renew.sh”:
| |
In the same directory where docker-compose.yml is located:
“start.sh”:
| |
“start_nologs.sh”:
| |
“restart.sh”:
| |
“restart_nologs.sh”:
| |
Cron
sudo crontab -e
VPS:
0 4 1 * * /bin/bash /root/certbot_renew.sh
Home Server:
2 4 1 * * systemctl restart zerotier-one
