caddycaddyfile

Caddy reverse proxy, prioritize files, then reverse_proxy


I got trouble using Caddy v2, while in v1 I never have such trouble

I want to prioritize:

file_server if started with /upload/*
reverse_proxy to 127.0.0.1:9090 if started with /api/*
else reverse_proxy to 127.0.0.1:3000

But seems I cannot get it properly work using v2, I've tried a lot (with matchers, changing port because 127.0.0.1 always 404 but localhost didn't, etc) but seems the 127.0.0.1:3000 always prioritized instead of file_server even when file exists, because it have wildcard?

{
        debug
        auto_https off
        log {
                output stdout
                level DEBUG
        }
        local_certs
}

127.0.0.1:80, localhost:80 {
        root ./svelte/dist
        file_server /upload/* browse
        reverse_proxy /api/* 127.0.0.1:9090
        reverse_proxy * 127.0.0.1:3000
}

Solution

  • Nevermind, got the answer https://caddy.community/t/v2-hard-to-make-it-right/13394/2

    127.0.0.1, 127.0.0.1:80, localhost, localhost:80 {
            handle /upload/* {
                    root ./svelte/dist
                    file_server browse
            }
    
            handle /api/* {
                    reverse_proxy 127.0.0.1:9090
            }
    
            handle {
                    reverse_proxy 127.0.0.1:3000
            }
    }