Proxy pass and rewrite

1. Caddy version (caddy version):

v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

2. How I run Caddy:

a. System environment:

Ubuntu 18

b. Command:

caddy start

d. My complete Caddyfile or JSON config: {
  route {
    rewrite * /status/Mlm1zrAx
    reverse_proxy {
      header_up Host {http.reverse_proxy.upstream.hostport}
  #tls {
  #  on_demand

3. The problem I’m having:

I have status pages which are located at addresses like{id}
Now I want users to be able to use custom domains which will be redirected using CNAME.

To begin with this task I decided to try something simple. When user goes to I want that he’s proxied to The “Mlm1zrAx” is just hardcoded for now. But of course I want that it’d be transparent for user, meaning it’s not a redirect but proxy, so that url doesn’t change.

Next step is to proxy: custom-domain.com, so that I can link users domain to my status page.

4. Error messages and/or full log output:

5. What I already tried:

I know that I probably missing something simple, and I don’t fully understand web servers configuration.

What I tried is I actually created the caddyfile, and tried to use rewrite + reverse_proxy.

However what I get right now, is that files served from have wrong Content-Type. All files (css/js) have text/html, so as a result I got " We’re sorry but pinger doesn’t work properly without JavaScript enabled. Please enable it to continue."

6. Links to relevant resources:

I think you want to do your rewrite like this:

rewrite * /status/Mlm1zrAx{uri}

The difference is that this will prefix all URLs, but what you were doing was rewriting all URLs to just /status/Mlm1zrAx, meaning every request, even the ones for JS files, were being rewritten to exactly /status/Mlm1zrAx. Instead, I think you want to proxy to /status/Mlm1zrAx/js/app.js or something like that.

Hm, I guess not. Look, the js/css files are located at

So, when user goes to it should behave like he opened{id}. And if I go directly to{id}, then all the js/css are loaded at

I don’t know if it may help, but previously when I tried to do this with nginx, I found a sample config which had sub_filter and he kind of replaced ulrs in html code or something like that

Then you only want to match requests to /?

Do this instead:

rewrite / /status/Mlm1zrAx

But like you said, ultimately you’ll probably need to filter the responses, which is not fun.

@matt is working on a plugin that does that, but it’s not open sourced yet, but will be soon:

1 Like

Strange, right now I get redirected to the login page.

However if I go to it’s not under authorization, I can see the page I need.

I’m not sure I understand rewrite directive correctly.

If I have rewrite * /bar, it means that if I go to I’ll get redirected to, right?

Then, even if rewrite / /status/some-id is better it shouldn’t affect. In my case if I entered I’ll get get proxied to, right? Like, no matter what user typed after, I’ll get redirected exactly to /status/some-id

Path matching in Caddy v2 is exact-match, so rewrite / /bar will only rewrite requests on / and will not rewrite requests on /foo.

The reason you’re getting kicked to the login page is likely because the authentication cookie is only stored for the domain, and not

Ah well, so do I get it right. I go to and receive javascript files from These javascript works like “When user on the root route “/” he should be redirected to login page”. Since the javascript doesn’t know that he was served from /status/{id}.

So I need to have a separate repository for I guess…

This topic was automatically closed after 30 days. New replies are no longer allowed.