1. Caddy version (caddy version
):
v2.2.1
2. How I run Caddy:
Docker, from the official image
a. System environment:
Docker
b. Command:
docker compose up -d
c. Service/unit/compose file:
reverse-proxy:
image: <REDACTED>:latest
restart: always
container_name: reverse-proxy
volumes:
- $HOME/data/static:/static
- $HOME/data/caddy/config:/config
- $HOME/data/caddy/data:/data
environment:
<REDACTED>
ports:
- 80:80
- 443:443
networks:
- <REDACTED>
d. My complete Caddyfile or JSON config:
www.{$CLIENT_DOMAIN}, {$CLIENT_DOMAIN} {
handle_errors {
@maintenance expression {http.error.status_code} == 502
rewrite @maintenance index.html
root * /etc/caddy/maintenance_page
file_server
}
# Rules
@users path_regexp ^/users/?
@trailing_slash path_regexp ^/(.*)/$
# Remove trailing slashes
rewrite @trailing_slash /{1}
# Force a redirect
# redir 301 {
# if {path} not /
# if {path} ends_with /
# / {rewrite_uri}
# }
# Redirect the old users to the new admin
redir @users https://{$ADMIN_DOMAIN}
# Special mappings
redir 301 {
<REDACTED>
}
reverse_proxy /sitemap.xml {$API_CONTAINER_URL}
reverse_proxy {$CLIENT_CONTAINER_URL}
encode gzip
}
3. The problem I’m having:
After being told that Caddy v1 was EOL, I have set aside time to migrate to the new version.
I am sorry to say, but since the migration from v1 to v2 the docs have become unreadable and really difficult to understand. What before was easy to achieve, is now unclear and has become a sort of try-fix-rince-repeat cycle.
I have been working on this for the past two days, and I can’t seem to figure this out. I am trying to achive something very simple:
- When the service is not available, show a maintenance page. This is working, although it needs some tuning
- When the URL starts with
/users/
, redirect to another URL (not sure 100% working) - Remove trailing slashes from any URL. Not working, all the answers I have found are for v1
- Global error catcher. No idea is this is possible, but I have multiple domains and I need to show a generic maintenance page when the service in one of those is not available
- An old question of mine: https://caddy.community/t/v1-rewrite-with-url-parameters/10612?u=ruben1691
I apologize if I sound quite rude, but as already said the documentation is just not up to what it was in v1. And I am starting to get frustrated.
Thanks to anyone willing to lend a hand
4. Error messages and/or full log output:
5. What I already tried:
All I have tried is listed in the Caddyfile above