V2: how can caddyfile reverse_proxy to JSON

1. Caddy version (caddy version):

v2.1.1

2. How I run Caddy:

in a terminal:
./caddy run -config caddy.json

a. System environment:

ubuntu 1804

b. Command:

./caddy run -config caddy.json

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

{
    "apps": {
        "http": {
            "servers": {
                "example2": {
                    "listen": [
                        "127.0.0.1:2016"
                    ],
                    "routes": [
                        {
                            "handle": [
                                {
                                    "handler": "reverse_proxy",
                                    "transport": {
                                        "protocol": "http",
                                        "read_buffer_size": 4096
                                    },
                                    "upstreams": [
                                        {
                                            "dial": "127.0.0.1:8080"
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
        }
    }
}

3. The problem I’m having:

now, i want to proxy a /subpath to 127.0.0.1:8080
in caddy1, i can do it:

127.0.0.1:2016 {
proxy /subpath 127.0.0.1:8080
}

in caddy2, how do i need to write the json file ???

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

The easiest thing to do if when learning to write JSON configs with Caddy is to write what you want as a v2 Caddyfile then adapt it to JSON with the caddy adapt command.

In Caddy v2, it would look like either of these, depending on whether your upstream service expects the subpath to be stripped or not.

With stripping:

handle_path /subpath/* {
	reverse_proxy 127.0.0.1:8080
}

Without stripping:

reverse_proxy /subpath/* 127.0.0.1:8080