Reverse proxy for POST, file server for GET

1. The problem I’m having:

Hello! I’m trying to get Caddy to both reverse proxy POST requests to another port on localhost, and to act as a file server for GET requests. I’d prefer to use the command line interface if possible, or otherwise a Caddyfile. I tried searching, but I couldn’t find anything on this.

2. Error messages and/or full log output:


3. Caddy version:


4. How I installed and ran Caddy:

I followed the usual method for debian, i.e. adding the custom repo.

a. System environment:

Debian 11.7, x86-64, with systemd, without docker.

b. Command:

I tried asking Google Bard, but I think it made it up. It said to run both of these commands:

caddy reverse-proxy --from --to --method POST
caddy file-server --root /path/to/your/static/files --domain

c. Service/unit/compose file:


d. My complete Caddy config:

[none - I’m trying to use the CLI]

5. Links to relevant resources:


I’m mobile now so I can only be brief, but can expand later if still necessary.

You’ll have to use the Caddyfile. I wouldn’t take Bard’s answers as accurate for such usages. What you need is the method subdirective of the reverse_proxy directive. See the Rewrite section here.

Brilliant, thank you. Would I be right in thinking that this is an example of a Caddyfile that achieves this goal?

:80 {
    reverse_proxy localhost:8080 {
        method POST

I know AI is inaccurate, particularly for these things, but Bard suggested this:

:80 {
    route {
        POST /* {
            reverse_proxy localhost:8080  # Replace with the address of your backend server
        GET /* {

Is one of these better than the other, do you know?

Oh, sorry, I misunderstood the question. I thought you want to convert POST to GET.

To confirm, you want POST requests to be reverse_proxy-ed but GET requests to go to file_server, right?

If yes, then you’re looking for this: {
   @post method POST
    @get method GET

    reverse_proxy @post localhost:8080
    file_server @get
1 Like

You are a gentleman and a scholar, thank you sir!


I’d do it like this: {
	@proxy not method GET
	reverse_proxy @proxy localhost:8080


This avoids needing two matchers, and it makes sure all methods are covered (including DELETE and PUT, etc).

1 Like

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