I’ve found a way to configure private, custom domains for web-apps I have running on my computer. So instead of having to remember and type “localhost:4333”, I can simply navigate to “appname.localhost”. I love it!


Here’s how the system works:

  1. Each app is set up as a launchd daemon listening on a unique port. Here’s an example plist.

  2. I configure /etc/hosts to redirect traffic to these domains to 127.0.0.1 instead.

  3. I then run and configure Caddy to redirect traffic from 127.0.0.1 to the right port for the domain.

So, if I’m running an app on port 5050, I will have a corresponding entry in /etc/host:


127.0.0.1 inclouds.localhost


and a section in my Caddyfile like this:


inclouds.localhost {
    reverse_proxy localhost:5050
    tls internal
    encode gzip zstd
}

This is working well but I’d really like to see this process simplified. How cool would it be to install or uninstall apps to .localhost domains with a single command, instead of manually editing three files? But that’s a project for another day.


Thanks for reading!


Update: cristóbal came up with a command using dnsmasq that makes this even better!