I will, for this example, be setting up a relay for Syncthing on a Debian install, but this is applicable to a range of services you may want to self-host.
This tutorial assumes you already have a domain and know how to configure the nameserver, and that your server is already exposed to the internet
First, install the service you want to run sudo apt
install syncthing-relaysrv
Ensure the systemd service is started with systemd
enable strelaysrv
systemd start
strelaysrv
Check if everything is working with systemd status
strelaysrv
If everything is in order, then move on to installing a
reverse proxy. We will be using caddy as our reverse proxy
sudo apt install caddy
Caddy is easy to configure. Simply create a text file named
Caddyfile at /etc/caddy/ touch
/etc/caddy/Caddfile
Format it like this
{
name@example.com
}
strelay.example.com { reverse_proxy localhost:22067 } `
Now set your nameserver so that strelay.example.com points to the IP address of your server, and when someone connects at strelay.example.com, they will be put through to the service listening at 22067, which is the default port for the syncthing relay. The subdomain can be changed to anything. If you want to add additional services, format it like this:
{
name@example.com
}
strelay.example.com
{
reverse_proxy localhost:22067
}
radicale.example.com
{
reverse_proxy localhost:1234
}
By default, services you start will be available only at local
addresses on the machine (localhost) and each service will be
listening at a particular port, which can typically be
customized. The reverse proxy accepts visitors from the outside
and connects them to the appropriate port
Caddy also automagically obtains a certificate from LetsEncrypt on your behalf, so users can connect securely over https