Handle ordering does not work

1. Caddy version (caddy version):

v2.5.0 h1:eRHzZ4l3X6Ag3kUt8nj5IxATprhqKq/wToP7OHlXWA0=

2. How I run Caddy:

a. System environment:

Distributor ID:	Ubuntu
Description:	Ubuntu 20.04 LTS
Release:	20.04
Codename:	focal

b. Command:

caddy run --config ~/Caddyfile

d. My complete Caddyfile or JSON config:

x.com:443 {
    log

    @websockets {
        header Connection *Upgrade*
        header Upgrade websocket

        #: https://caddy.community/t/caddy-v2-how-to-proxy-websoket-v2ray-websocket-tls/7040/13
    }

  handle_path /path {
    reverse_proxy @websockets localhost:10000 {
      header_up -Origin
    }

   handle {
     file_server browse {
        root {env.HOME}/Downloads
     }
   }
  }
}

3. The problem Iā€™m having:

Without the last handle block, my reverse proxy works fine. But with that block added, nothing works (not the reverse proxy or the file server).

When looking at the adapted JSON config, it seems the last handle block is still matching on /path/. But I might be mistaken.

4. Error messages and/or full log output:

5. What I already tried:

I tried changing the last handle block to handle / and hanle_path /, which made the reverse proxy work again, but the file server still did not work.

6. Links to relevant resources:

Path matching is exact in Caddy. You used handle_path /path which will only match requests to exactly /path and nothing else, not /path/foo etc.

What exactly are you trying to do? What request paths should serve what?

1 Like

I had a misplaced }. This worked:

x.com:443 {
    # log

    @websockets {
        header Connection *Upgrade*
        header Upgrade websocket

        #: https://caddy.community/t/caddy-v2-how-to-proxy-websoket-v2ray-websocket-tls/7040/13
    }

   handle_path /path {
    reverse_proxy @websockets localhost:10000 {
      header_up -Origin
    }
   }

   handle {
     file_server browse {
        root {env.HOME}/Downloads
     }
   }
}
1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.