Caddy is a modern, easy-to-use reverse proxy server that supports flexible configurations, including wildcard domain handling.
#### Installation of Caddy 1. **Install Caddy**: You can install Caddy on macOS using Homebrew: ```sh brew install caddy ```
2. **Caddyfile Configuration**: Create a `Caddyfile` to configure your reverse proxy rules. ```sh nano /usr/local/etc/Caddyfile ```
3. **Update the Caddyfile**: Use the following configuration to set up your proxy rules:
{ auto_https off } # Handle rest.livecode.world http://rest.livecode.world { reverse_proxy http://localhost:9090 } # Catch-all for livecode.world and its subdomains http://*.livecode.world, http://livecode.world { reverse_proxy http://localhost:3000 } # Catch-all for thought.garden and its subdomains http://*.thought.garden, http://thought.garden { reverse_proxy http://localhost:3000 } # Catch-all for localhost and its subdomains http://*.localhost, http://localhost { reverse_proxy http://localhost:3000 }
4. **Run Caddy**: Start Caddy with your configuration file. ```sh sudo caddy run --config /usr/local/etc/Caddyfile ```
### Explanation - **Global options block**: Optional configuration for global settings, such as your email for automatic TLS certificates. - **Wildcard domain**: The `*.localhost, localhost` matches all subdomains and the base domain `localhost`, proxying them to `localhost:3000`. - **Specific domain**: The `rest.livecode.world` domain is explicitly matched and proxied to `localhost:9090`.
### Setting Up `/etc/hosts` Ensure your `/etc/hosts` file correctly maps your domains to `localhost`.
127.0.0.1 localhost 127.0.0.1 thought.garden 127.0.0.1 livecode.world 127.0.0.1 rest.livecode.world # Add other domains as needed
### Summary Using Caddy provides a more flexible and straightforward way to handle reverse proxy configurations, including wildcard domains and specific domain rules. This configuration ensures that requests are routed based on the domain name specified in the `Host` header of incoming requests. If you still want to use Tinyproxy and need to handle many domains, you would need to manually list all domains in the configuration or use another approach to generate the configuration dynamically, which can become cumbersome. Caddy simplifies this process significantly.