A Caddyfile for hosting your clearnet domain and all subdomains on Tor
After installing torrc
and pointing your hidden service to your Caddy server:
# Redirect base domain to www subdomain
http://example.onion {
redir http://www.example.onion{uri}
}
# Proxy all subdomains of example.com
http://*.example.onion {
@hostnames header_regexp hostname Host (\S+)\.example\.onion
# note the backslashes before the dots
handle @hostnames {
reverse_proxy {re.hostname.1}.example.com:443 {
header_up Host {re.hostname.1}.example.com
transport http {
tls
}
}
}
}
Replacing example.onion
with whatever your onion hostname is, e.g. xoe4vn5uwdztif6goazfbmogh6wh5jc4up35bqdflu6bkdc5cas5vjqd.onion
, and example.com
with your clearnet domain.
For example this configuration allows:
- discuss.privacyguides.net to be accessed via http://discuss.6xotdxvg7pexnean3xu6b7ivs7g52zcwsdbnz4mdm4byivc3yfv65aid.onion/
- invidious.privacyguides.net to be accessed via http://invidious.6xotdxvg7pexnean3xu6b7ivs7g52zcwsdbnz4mdm4byivc3yfv65aid.onion/
- etc.
...without configuring Tor on each server.