Domains for local dev servers
I have a bunch of servers running locally, and I find it quite inconvenient (and inelegant) to access them as localhost:8081
, localhost:9000
, and so forth.
With Caddy, the amazing Web server written in Go, setting up “domains” for local servers is easy as pie.
Let's say you have a local server listening on port 9000. After installing Caddy, run
caddy reverse-proxy --from myserver.localhost --to :9000
and open https://myserver.localhost
. Boom: your server at localhost:9000
answers!
Note the https
protocol — Caddy even provides local TLS certificates. (Caddy
generates and installs a CA root automatically on first invocation; you might have to enter your local user's password if the OS asks you to. And you might have to run caddy trust
. I tested on macOS with a non-admin user with sudo
privileges, and I did not need caddy trust
, but your mileage may vary.)
If you want to proxy more servers this way, create a file named Caddyfile
and enter host configuration like so:
myapp.localhost {
reverse-proxy :9000
}
myhugoblog.localhost {
reverse-proxy :1313
}
Repeat this pattern to add local servers as needed.
Then run
caddy
in the directory where you created the Caddyfile.
That's it! No messing around with DNS entries or TLS certificate files.