dabaichi
(dabaichi)
June 7, 2020, 12:03pm
1
1. Caddy version (caddy version
):
v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=
2. How I run Caddy:
docker run caddy
a. System environment:
docker
b. Command:
docker run caddy
c. My complete Caddyfile or JSON config:
example.com
root /static/* /var/www
file_server
reverse_proxy /* localhost:5000
3. The problem I’m having:
THIS MAY BE A NOOB QUESTION
There do is an example config for reverse proxy
example.com
root * /var/www
reverse_proxy /api/* localhost:5000
file_server
But I need a reverse
config:
Serve static files having a path starting with /static/
and proxy requests for everything else
I use the follow config:
example.com
root /static/* /var/www
file_server
reverse_proxy /* localhost:5000
but it seems dosen’t work.
4. Error messages and/or full log output:
5. What I already tried:
6. Links to relevant resources:
opened 09:53AM - 07 Jun 20 UTC
closed 12:04PM - 07 Jun 20 UTC
question
THIS MAY BE A NOOB QUESTION
There do is an example config for reverse proxy
…
https://caddyserver.com/docs/caddyfile/patterns#reverse-proxy
```caddy
example.com
root * /var/www
reverse_proxy /api/* localhost:5000
file_server
```
But I need a `reverse` config:
Serve static files having a path starting with `/static/` and proxy requests for everything else
I use the follow config:
```caddy
example.com
root /static/* /var/www
file_server
reverse_proxy /* localhost:5000
```
but it seems dosen't work.
abiosoft
(Abiola Ibrahim)
June 7, 2020, 12:41pm
2
reverse_proxy
comes before file_server
in the directive order, I would recommend using a route
to take control of the order.
example.com
route {
file_server /static/* {
root /var/www
}
reverse_proxy localhost:5000
}
2 Likes
dabaichi
(dabaichi)
June 7, 2020, 1:47pm
3
I use the following config:
example.com
route {
file_server /static/* {
root /var/www
}
}
reverse_proxy localhost:5000
and it works.
TIPS
if you are using the following config:
file_server /static/* {
root /var/www
}
and visit: /static/1.html
the real file path caddy read is: /var/www/static/1.html
not like nginx will read: /var/www/1.html
if running caddy in docker, DO NOT forget copy files to docker image or mount the directory to container.
abiosoft
(Abiola Ibrahim)
June 7, 2020, 5:02pm
4
Thanks to the flexibility of Caddy 2, that can be fixed easily
route /static/* {
uri strip_prefix /static
file_server {
root /var/www
}
}
matt
(Matt Holt)
June 7, 2020, 11:23pm
5
That works by chance.
Here is the order of the directives: Caddyfile Directives — Caddy Documentation
And here’s a page that describes your scenario exactly (but with a different directive) and explains why it is this way and how to use the route
directive: route (Caddyfile directive) — Caddy Documentation
You could also use handle
instead.
And here’s a wiki post that goes into more detail about writing Caddyfiles: Composing in the Caddyfile
system
(system)
Closed
July 7, 2020, 12:03pm
6
This topic was automatically closed after 30 days. New replies are no longer allowed.