1. Caddy version (caddy version
):
Caddy 2.4.3 w/ caddy-dns cloudflare
2. How I run Caddy:
a. System environment:
Dietpi 7.4 on Raspberry Pi 4B, systemd running Caddy as a service (using package alongside cloudflare custom package following documentation guide).
b. Command:
sudo systemctl start caddy
c. Service/unit/compose file:
N/A - Caddy runs fine through systemd
d. My complete Caddyfile or JSON config:
# Using 01DNS method for TLS as I am behind a CGNAT.
{
acme_dns cloudflare APIKEY
}
# Proxy raspberry pi DNS blocker webui to 'adguard.postulat.es'. Domain mapped to 10.0.0.2 Caddy server for local access.
adguard.postulat.es {
# Adguard is running on same raspberry pi server as Caddy.
reverse_proxy http://localhost:8083
}
# Proxy UDM router webui to 'unifi.postulat.es'. Domain mapped to 10.0.0.2 Caddy server for local access.
unifi.postulat.es {
reverse_proxy https://10.0.0.1 {
transport http {
tls_insecure_skip_verify
}
}
}
# Proxy QNAP NAS admin webui to 'qnap.postulat.es'. Domain mapped to 10.0.0.2 Caddy server for local access.
qnap.postulat.es {
#QNAP NAS is on 10.0.0.222 and is running several docker containers. Port 8080 is webui for system.
reverse_proxy http://10.0.0.222:8080
}
# Attempt to proxy various QNAP containers to subdirectories of root domain rather than subdomains. Domain is mapped to 10.0.0.2 Caddy server for local access.
postulat.es {
# Method for radarr and sonarr taken from Caddyfile suggestion found on Google. Appears to work using 'base url' change.
redir /radarr /radarr/
redir /sonarr /sonarr/
# I redir-ed qnap to copy the approach for radarr and sonarr.
redir /qnap /qnap/
reverse_proxy /radarr/* {
to http://10.0.0.222:7878
}
reverse_proxy /sonarr/* {
to http://10.0.0.222:8989
}
***[QNAP Reverse Proxy - see below for the two attempts I have used to do this]***
}
3. The problem Iâm having:
A. Using Caddy to access various home server applications
I own a domain which I have mostly mapped to the local (10.0.0.2) IP address of my Raspberry Pi running Caddy. I am running a reverse proxy and can currently access several applications through subdomains, listed above.
I am separately considering exposing some Caddy services through a password-protected Cloudflare/Argo tunnel (because we have CGNAT I canât use Caddy directly with port forwarding), but that is secondary to just having my various services available under a domain mapped to local IPs.
B All working fine for services that let me modify base urls
I would like to expose the various applications running in docker on my QNAP NAS on the root postulat.es domain rather than subdomains. I found a few examples of how to do this online and have got Sonarr and Radarr working by copying these examples and making the limited necessary adjustments.
I also do not anticipate any issues with a few other containers, as their webuis or configuration files all let me adjust the âbase urlâ for those services. All of these services originally run at the domain level
(example. com), but can be altered so they run at [serverip:port]/service/. As I understand it, this means that there are no issues with me using postulat.es/service, because they map across properly (sorry that my terminology is terrible).
C QNAP webui does not work and I canât change the base url
My QNAP NAS has a web ui that lets me manage updates and generally administer the server. The uiâs login page and operations load at 10.0.0.222:8080/cgi-bin/, and navigating to 10.0.0.222:8080 automatically redirects to 10.0.0.222:8080/cgi-bin. There does not seem to be any way to change the base url for this service as can be done with Sonarr and Radarr. As explained in part 5 below, I have tried two attempts to forward the QNAP web ui, but neither work.
I would like to know if it is possible to get this working so that navigating to postulat.es/qnap/ takes me to the QNAP web ui. I am currently using qnap.postulat.es/ to get to the webui, but I would prefer to have all my docker-related services exposed at the top-level of the domain.
4. Error messages and/or full log output:
N/A I have not received any error messages.
5. What I already tried:
I originally tried to just copy the approach for Sonarr and Radarr that I used, which I found from Google searches.
reverse_proxy /qnap/* {
to http://10.0.0.222:8080
}
This produces an âpage not foundâ error message (see bottom of post) that I think comes from the QNAP webui trying to load its interface but (I assume) not being able to find files where it expects them. The error message looks like this:
From looking online, this seems to have been a known issue. One poster on this forum dubbed this the âsubfolder problemâ and noted there are three ways to get around this (their post is from June 2020):
-
Fix âupstreamâ by using base urls. This isnât an option as the QNAP webui and OS doesnât allow you to change the base url, from the searches Iâve done on Google.
-
Use a subdomain instead of subfolders. I am doing this now, but am posting to see if a subdirectory approach is possible as I would prefer that.
-
Using HTML filtering or rewriting. I am struggling to understand how this works and do not fully understand exactly what to put in my Caddyfile. Itâs also not clear to me if there was a fix at the time they wrote this, or if it was under development, as their post notes that there is a Caddy module being developed, but I do not see how it would remove the /qnap/ from my url but rather just replace it.
I saw several references online to settings in Caddy v1 that seem to suggest the âwithoutâ directive, but read that these were considered âhacksâ and are âcompletely unnecessaryâ as of Caddy v2. I did find a separate blog post that provides tips on upgrading from Caddy v1 to Caddy v2, which seems to suggest some directives that can replace the âwithoutâ directive (my emphasis):
Requests to
https://example.com/api/foo/bar/
is redirected tohttps://backend.com/api/foo/bar/
.
To remove the path prefix:
#v1
proxy /api https://backend.com {
without /api
}
Requests to
https://example.com/api/foo/bar/
is redirected tohttps://backend.com/foo/bar/
.
v2 doesnât havewithout
directive, instead you need to useroute
the request and remove the prefix usinguri strip_prefix
:
#v2
route /api/* {
uri strip_prefix /api
reverse_proxy https://backend.com
}
v2.1 adds
handle_path
directive which integrates prefix stripping:
#v2.1
handle_path /api/* {
reverse_proxy https://backend.com
}
I tried a version of the v2 approach (the 2.1 also doesnât work):
route /qnap/* {
uri strip_prefix /qnap
reverse_proxy 10.0.0.222:8080
}
But this just gives me a blank page at postulat.es/redirect.html?count=0.13713111451312998.
Is there any hope for me?
This seems to have been an issue for other people, and is at least a significant enough happening with reverse proxy use that several web self-hosted web applications let you specify custom base urls. I have tried my best, but my lack of technical knowledge along with a lot of essentially legacy references to (possible?) solutions using Caddy v1 which are no longer working means I am at a loss as to how to get the QNAP webui to show up in a subfolder.
I would be extremely grateful if the community could let me know if thereâs something Iâm missing here, or if this is just not feasible at the moment.
6. Links to relevant resources:
Iâve posted links to the blogposts I read above. There were a good dozen and more of posts on this forum and other blogs online, but none of them were of help to me (this is probably also due to my inability to make sense of them; I am trying to learn.
The picture of the error message I get when running a âvanillaâ reverse proxy configuration mentioned above is:
Thanks
Thanks a lot for taking the time to read, and also in advance in case anyone is able to help with this. Thanks to the development community for making Caddy: I am not very technical at all but have been blown away by how easy to use Caddy is otherwise from this admittedly fairly minor issue.