Don’t know how to title this but I’m sure it’s interesting for some and should be found that way^.
I’m mostly writing this because of the mime-error. If anyone knows more about that I would be happy to hear you.
I’ll simply describe two Caddyfiles with the only difference being in there matcher (/
and *
).
In both cases, we access a backend server using the reverse_proxy directive.
Caddy version: v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=
Caddyfile #1
Let’s have a look at the first case:
sub.domain.tld {
reverse_proxy / localhost:19999
}
And at the website when opening sub.domain.tld in the browser. Console output:
Refused to apply style from 'https://sub.domain.tld/main.css?v=5' because its MIME type ('') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Refused to execute script from 'https://sub.domain.tld/main.js?v20190905-0' because its MIME type ('') is not executable, and strict MIME type checking is enabled.
Refused to execute script from 'https://sub.domain.tld/dashboard.js?v20190902-0' because its MIME type ('') is not executable, and strict MIME type checking is enabled.
And as you might guess already the website is shown without CSS and is non-functional due to missing js. Images aren’t shown either.
No other files are requested leading to only having 5 requests made, each with status-code 200.
Caddyfile #2
now let’s change the matcher to *
.
sub.domain.tld {
reverse_proxy * localhost:19999
}
Shouldn’t change much, or?
Now the website loads correctly, with CSS, JS and images. And now we have around 37 network requests made, all with status code 200 [okay, one 404 but that file should be missing ]
So what happened?
In the second Caddyfile, we used a wildcard matcher. Proxying everything to our backend.
but in the first Caddyfile, we used a strict path matcher which only matches the exact path and no other.
A path matcher with a wildcard (/*
) should have worked too. But /*
can be shortened to *
(afaik - don’t see any difference behind).
reverse_proxy docs for fast access:
But… I still don’t know why the mime error occurred instead of a 404 error or any other HTTP error.