1. The situation
Hello, after a bit of tinkering Caddy is working very nicely for my purposes, and I’ve almost got it doing exactly what I want. I’m hoping people here might be able to help me work out if/how I can configure the last bit of behaviour I’m looking for.
I’ve chopped out a few of the “info about the error”-type sections of this template accordingly.
1a. More details
I have a selfhosted Gitea server set up as https://git.tecosaur.net
, and it’s just for my own use.
I thought it would be neat if instead of having to do /tec/X
I could just do /X
and when a 404 occurs redirect to /tec/X
if that path does not produce a 404.
The config below almost does this, I’ve managed to get a blanket 404-rewrite rule working, e.g. https://git.tecosaur.net/golgi
successfully redirects to https://git.tecosaur.net/tec/golgi
. However, non-tec prefixed 404s like https://git.tecosaur.net/nope
get redirected to https://git.tecosaur.net/tec/nope
before 404ing a second time, which isn’t ideal.
I’d love it if I could configure this so that when the /tec/X
redirect also 404s the redirect is abandoned. E.g. https://git.tecosaur.net/nope
just leads to a 404 page for https://git.tecosaur.net/nope
as normal.
From what I read of how matches work, I can’t see an obvious way to do this, but I’m hoping other people might be able to shed more light on what is/isn’t possible.
3. Caddy version:
- 2.6.4
4. How I installed and ran Caddy:
- NixOS
4d. My complete Caddy config:
See golgi/caddy.nix at master - golgi - Code by TEC, the relevant excerpt of the Caddy file is as follows:
git.tecosaur.net {
log {
output file /var/log/caddy/access-git.tecosaur.net.log
}
@not_tec not path /tec/*
handle @not_tec {
reverse_proxy localhost:3000 {
@404 status 404
handle_response @404 {
redir * /tec{uri}
}
}
}
handle {
reverse_proxy localhost:3000
}
}