1. The problem I’m having:
I am desperately trying to setup custom user domains to map to full path url of my product. (and I’m very new to Caddy)
For example: User types in the browser a url with subdomain that they control, and sees a page that is hosted elsewhere with a full path url.
https://blog.userdomain.com
→ https://app.myproduct.com/user/blog-123/hello-world
I understand that reverse_proxy
upstream addresses cannot contain paths or query strings and I should use rewrite and this is something I am unable to figure out.
There is one nuance, the path/segment blog-123
will need to be dynamically retrieved from a backend/storage based on the host. To make that happen I put a NodeJS/Express server that Caddy calls to retrieve that dynamic piece of information, but from then on I am unable to route the user the page using NodeJS/Express. I’m getting series of issues when I try that as I need to handle each request browser makes, like js, css, fonts, assets etc. I think I’m approaching this incorrectly.
One other thing I tried was just to retrieve the dynamic id/path in NodeJS/Express side and return that back to Caddy as a header to then use it to rewrite the full url, which I’m failing to do so as well.
Overall I’m a bit lost, I’m not even sure if I’m trying the impossible or what am I missing to make this happen.
Another thought I am having is to put the NodeJS/Express server first, retrieve the dynamic value and then pass it onto Caddy, but I am afraid I’ll have issues eventually with on_demand_ssl as Caddy will be the second layer in line.
2. Error messages and/or full log output:
I don’t necessarily have error messages, I’m just unable to figure out the approach.
When I try NodeJS to proxy all the requests, I get mime types errors, though irrelevant I assume.
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
3. Caddy version:
v2.9.1 h1:OEYiZ7DbCzAWVb6TNEkjRcSCRGHVoZsJinoDR/n9oaY=
4. How I installed and ran Caddy:
brew install caddy
a. System environment:
macOS 15.3.2
Eventually I’ll use Docker but I’m trying to make this work end to end locally first before I move on.
b. Command:
caddy run
c. Service/unit/compose file:
Not using Docker yet.
d. My complete Caddy config:
I’m sorry I don’t have a config that adds any value, I’m trying to figure out what I am supposed to do.