Northrop
(Northrop)
May 27, 2020, 3:01pm
1
1. Caddy version (v2
):
2. How I run Caddy:
a. System environment:
Ubuntu 20.04 LTS, Package Installed Caddy
b. Command:
systemctl (start,stop,restart,status) caddy.service
d. My complete Caddyfile or JSON config:
https://home.example.com {
reverse_proxy * 192.168.125.11:443 {
header_up X-Forwarded-Proto https
header_up Host home.example.com
transport http {
tls_insecure_skip_verify
}
}
}
https://cloud.example.com {
reverse_proxy * 192.168.125.12:443 {
rewrite /nextcloud /
header_up Host cloud.example.com
header_up X-Forwarded-Proto https
transport http {
tls_insecure_skip_verify
}
}
}
https://cad.example.com {
rewrite /Cad /
reverse_proxy * 192.168.125.13:80 {
header_up Host bauad.example.com
header_up X-Forwarded-Proto https
}
}
3. The problem I’m having:
I have the simple problem that I would have access to the subfolders of the respective web server with the reverse proxy.
(1) The first functions as far as it has no subfolder.
proxy: https:// home.example. com direct: https:// 192.168.125.11
(2) The second:
proxy: https:// cloud.example. com direct: https:// 192.168.125.12/nextcloud
(3) The Third:
proxy: https:// cad.example. com direct: http:// 192.168.125.13/cad
I do not care whether I go directly to the respective folder or whether it is forwarded.
2: https://cloud.example.com/nextcloud
3: https://cad.example.com/cad
are also solutions that are considered possible.
5. What I already tried:
as seen in the caddyfile above, I have already tried “rewrite”. Even with “redir” it didn’t work.
This seems to be a simple configuration but I haven’t found a working solution.
jok
(Jochen)
May 27, 2020, 4:44pm
2
I just had to configure something similar (my path on the upstream is a bit more complicated).
at the moment i use this:
www.example.com {
tls mail@example.com {
#ca https://acme-staging-v02.api.letsencrypt.org/directory
}
route {
uri replace / /some/path/on/upstream/ 1
reverse_proxy http://upstream.example.com {
import someheaders
}
}
}
the final “1” on the uri line is importatnt to get things working, without it the “/” got replaced multiple times
matt
(Matt Holt)
May 27, 2020, 4:46pm
3
To prepend to the path, use rewrite instead:
rewrite * /some/path/on/upstream{uri}
@Northrop I wrote a very comprehensive wiki article about composing routes in the Caddyfile – it will answer your question! (As will the docs page for the route directive.)
Web server config files are mostly about expressing HTTP handling logic. Often, various handlers or middlewares need to be “composed” to form a cohesive HTTP handler that returns the desired responses.
Structurally, config files are basically limited to two dimensions: rows and columns (or, lines and tokens). Syntactically, a config file’s second dimension can expand into more dimensions or scopes when blocks are opened (which are usually represented by curly braces { } and/or indentation, simi…
1 Like
jok
(Jochen)
May 27, 2020, 5:31pm
4
ok, that is more like my former apache config, were i used a RewriteRule with [L,P] to proxy it to the upstream.
It works (even without explicit route{} )
1 Like
Northrop
(Northrop)
May 28, 2020, 7:48am
5
To me, rewriting the URI seems the easiest. Because I don’t quite understand the matt documentation. I cannot draw a solution to my problem from the documentation.
The change with rewrite solves the problem for me: ERR_TOO_MANY_REDIRECTS
https://cloud.example.com {
route {
rewrite * /nextcloud{uri}
reverse_proxy * 192.168.125.12:443 {
header_up Host cloud.example.com
header_up X-Forwarded-Proto https
transport http {
tls_insecure_skip_verify
}
}
}
}
Northrop
(Northrop)
May 28, 2020, 8:18am
6
Ok, This was my mistake. i found the error. For the rewrite, the * had to be replaced by /
https://cloud.example.com {
route {
rewrite / /nextcloud{uri}
reverse_proxy * 192.168.125.12:443 {
header_up Host cloud.example.com
header_up X-Forwarded-Proto https
transport http {
tls_insecure_skip_verify
}
}
}
}
system
(system)
Closed
June 26, 2020, 3:01pm
7
This topic was automatically closed after 30 days. New replies are no longer allowed.