1. Caddy version (caddy version
): v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=
(Plugins DNS-Cloudflare and DNS-Hetzner)
2. How I run Caddy:
I’m Using a Caddyfile to configure caddy.
caddy start
I will configure it to be a service if configuration is successful (right now i’m still using HAProxy)
a. System environment:
Ubuntu 20.04 VPS on strato.de (likely a Hetzner machine)
b. Command:
caddy start
Paste command here.
d. My complete Caddyfile or JSON config:
{
acme_dns cloudflare ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}
*.mysaas.shop mysaas.shop {
reverse_proxy localhost:8091
@user {
host *.mysaas.shop
path *
}
handle @user {
rewrite * https://mysaas.shop/s/{http.request.host.labels.2}{uri}
}
}
3. The problem I’m having:
I am trying to achieve this:
I have a NextJS app which has subpaths /u/{username} for user controlled pages (small configurable shops).
However i want to enable users to get a subdomain via {username}.mysaas.shop.
The app has multiple locales (for now its english and german, but will likely be more in the future).
The locales are prepended to the path like this: /en-US/u/{username} or generally /{locale}/u/{username}.
If no locale is specified, the default app locale (en-US) will be used (/u/{username} defaults to english).
Users can also create custom pages which append to the userpath (/u/{username}/{custom-page})
I’m trying to rewrite {username}.mysaas.shop hosts to → mysaas.shop[/{locale}?]/u/{username}[/{custom-page}?].
So far my current config works when trying direct urls:
foo.mysaas.shop/bar → mysaas.shop/u/foo/bar (invisible to the browser)
However entering just foo.mysaas.shop leads to a redirect to → foo.mysaas.shop/u/foo
4. Error messages and/or full log output:
5. What I already tried:
I have tried to use different matchers for rewrites, eg.
if {path} not_starts_with {label2}
or
if {path} not_starts_with {locale} \n if {path} not_starts_with {label2}
however i cannot get rid of the initial redirect
Any ideas?