Issues with Reverse Proxy Configuration in Caddy Server

Title: Issues with Reverse Proxy Configuration in Caddy Server

Hello everyone,

I’m currently configuring a Caddy server and encountering an issue where requests to /api/v2/* return a 502 error when I remove a specific part of the configuration. However, when the configuration is included, everything works as expected.

Here’s the part of the configuration in question:

handle /api/v2/* {
    reverse_proxy http://127.0.0.1:10000
}

With the above configuration in place, requests to /api/v2/* are properly reverse proxied to http://127.0.0.1:10000 and function correctly. However, when I remove this block, I start receiving a 502 error for these requests.

Here’s the full configuration for context:

example.com {
    import log example.com
    import common

    handle /api/v2/* {
        reverse_proxy http://127.0.0.1:10000
    }
    handle_path /api/* {
        reverse_proxy http://127.0.0.1:8080 {
            @errors status 404
            handle_response @errors {
                reverse_proxy http://127.0.0.1:10000 {
                    rewrite /api{uri}
                }
            }
        }
    }
    handle /builder/* {
        reverse_proxy http://127.0.0.1:10000
    }
    handle {
        reverse_proxy http://127.0.0.1:10000 {
            rewrite /prefix{uri}
        }
    }
}

I have confirmed that the service on port 8080 correctly returns a 404 status code for nonexistent routes.

Could someone help me understand why removing the /api/v2/* handle causes a 502 error and how the fallback mechanism under handle_path /api/* is supposed to work? I’m trying to understand why the requests aren’t being captured and redirected to port 10000 as specified in the error handling block.

Thank you for your assistance!

Caddy version: v2.8.4

Hmm. Please enable the debug global option and show your logs. Would need to see the order of what happens for a single request

2 Likes

Thank you for your reply.

{
    "level": "debug",
    "ts": 1727663872.4190404,
    "logger": "http.handlers.reverse_proxy",
    "msg": "upstream roundtrip",
    "upstream": "127.0.0.1:10000",
    "duration": 0.000241584,
    "request": {
        "proto": "HTTP/2.0",
        "method": "POST",
        "host": "example.com",
        "uri": "/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0",
        "headers": {
            "Sec-Ch-Ua": [
                "\"Microsoft Edge\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""
            ],
            "X-Forwarded-Proto": [
                "https"
            ],
            "Sec-Fetch-Mode": [
                "cors"
            ],
            "Sec-Fetch-Site": [
                "same-origin"
            ],
            "Accept-Encoding": [
                "gzip, br"
            ],
            "X-Budibase-Api-Version": [
                "1"
            ],
            "Priority": [
                "u=1, i"
            ],
            "Content-Length": [
                "17"
            ],
            "Accept": [
                "application/json"
            ],
            "Sec-Ch-Ua-Mobile": [
                "?0"
            ],
            "X-Forwarded-Host": [
                "example.com"
            ],
            "Cf-Ray": [
                "8cb0d56288647c73-LAX"
            ],
            "User-Agent": [
                "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"
            ],
            "Cookie": [
                "REDACTED"
            ],
            "Sec-Fetch-Dest": [
                "empty"
            ],
            "Cdn-Loop": [
                "cloudflare; loops=1"
            ],
            "X-Budibase-App-Id": [
                "app_79a24f5a85c94e6c94c81448370a144a"
            ],
            "Origin": [
                "https://example.com"
            ],
            "X-Budibase-Session-Id": [
                "cf88312de49d446878b0f2f88f2664485"
            ],
            "X-Budibase-Type": [
                "client"
            ],
            "Sec-Ch-Ua-Platform": [
                "\"Windows\""
            ],
            "Content-Type": [
                "application/json"
            ]
        },
        "tls": {
            "resumed": false,
            "version": 772,
            "cipher_suite": 4865,
            "proto": "h2",
            "server_name": "example.com"
        }
    },
    "error": "net/http: HTTP/1.x transport connection broken: http: ContentLength=17 with Body length 0"
}

The above is what I get when I turn on debug mode (I remove some sensitive information)
It looks like 127.0.0.1:1000 didn’t get the body in the original request correctly.

Ah, the request isn’t responding with a 404, instead it’s producing an error. So your handle_response can’t run. You’ll need to figure out why your upstream app writes an invalid HTTP response (it’s invalid to say the content length is non-zero when the body is empty).

You could use handle_errors to handle the 502 error, you can’t use handle_response for that though because it’s an actual error and not a completed response that you can handle.

1 Like

Do you mean the service on port 8080 is not returning 404?

Oh misread, got the ports mixed up. But you only gave the last log entry which didn’t show the whole picture, I wanted to see all of the logs for a single request (including the debug log from the initial proxy on 8080 as well).

I have to assume that your API call has a POST body? In that case the problem is the proxy attempt to 8080 consumes the POST body, so it can’t be used in handle_response anymore (it’s now empty).

Caddy doesn’t buffer the request body. It’s a stream, so once it gets consumed, it’s gone.

We do have a request_buffers option but it doesn’t rewind to allow replay in this situation. That could be something we add in the future though.

So looking back at your original question, what’s wrong with the other config with path matching instead? That’s more efficient anyway because you avoid having to do two roundtrips in the case that it fails with the first upstream.

1 Like

Attached are the logs from the 8080 service, there is no difference in content when its log level is Debug or Info

2024-09-30T02:55:54.271Z INFO middleware/log.go:25 request {"code": 404, "method": "POST", "uri": "/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0", "ip": "***", "latency": "0ms"}


In fact, currently only POST /api/v2/* requests are not responded to correctly, I think because they are the only ones with a request body.

I meant Caddy’s debug logs. All of them. Not just the last one.

But either way, what I wrote previously still stands. Why were you trying to do this fallback thing anyway?

1 Like

I apologise for misunderstanding you as I was using a translator, I actually wanted to merge :8080/* and 10000:/api/* so I wrote this config.

Here are all of Caddy’s logs about the request.


# docker compose logs -f | grep /api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0

{"level":"debug","ts":1727663637.5844908,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_ip":"172.69.34.119","remote_port":"20932","client_ip":"172.69.34.119","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"X-Forwarded-Proto":["https"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Cdn-Loop":["cloudflare; loops=1"],"Cf-Ipcity":["Los Angeles"],"Content-Length":["17"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Accept":["application/json"],"Content-Type":["application/json"],"Origin":["https://example.com"],"Sec-Fetch-Dest":["empty"],"Cf-Postal-Code":["90017"],"Cf-Region-Code":["CA"],"Sec-Fetch-Mode":["cors"],"Cf-Metro-Code":["803"],"Referer":["https://example.com/"],"Priority":["u=1, i"],"Cf-Iplatitude":["34.05150"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"X-Budibase-Session-Id":["c1939c4195bb54a0b9f1a52fb548142f8"],"Cookie":["REDACTED"],"Cf-Ipcountry":["US"],"Cf-Iplongitude":["-118.27070"],"Cf-Ray":["8cb0cfa6de5c525d-LAX"],"X-Budibase-Api-Version":["1"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Site":["same-origin"],"Accept-Language":["zh-CN,zh;q=0.9,en-GB;q=0.8,en;q=0.7,zh-TW;q=0.6"],"Cf-Ipcontinent":["NA"],"Accept-Encoding":["gzip, br"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"X-Budibase-Type":["client"],"Cf-Region":["California"],"Cf-Timezone":["America/Los_Angeles"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"method":"POST","uri":"/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0"}

{"level":"debug","ts":1727663637.5875843,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"127.0.0.1:10000","duration":0.000398348,"request":{"remote_ip":"172.69.34.119","remote_port":"20932","client_ip":"172.69.34.119","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"Cf-Timezone":["America/Los_Angeles"],"Cf-Ipcity":["Los Angeles"],"Accept-Language":["zh-CN,zh;q=0.9,en-GB;q=0.8,en;q=0.7,zh-TW;q=0.6"],"Cf-Iplongitude":["-118.27070"],"Accept-Encoding":["gzip, br"],"Accept":["application/json"],"X-Forwarded-For":["172.69.34.119"],"Cookie":["REDACTED"],"Content-Type":["application/json"],"Cf-Metro-Code":["803"],"Cf-Iplatitude":["34.05150"],"X-Budibase-Session-Id":["c1939c4195bb54a0b9f1a52fb548142f8"],"Sec-Ch-Ua-Mobile":["?0"],"X-Budibase-Type":["client"],"X-Forwarded-Proto":["https"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Sec-Fetch-Dest":["empty"],"Cf-Ipcountry":["US"],"Sec-Fetch-Site":["same-origin"],"Content-Length":["17"],"Cdn-Loop":["cloudflare; loops=1"],"Referer":["https://example.com/"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Origin":["https://example.com"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"Sec-Fetch-Mode":["cors"],"Cf-Ray":["8cb0cfa6de5c525d-LAX"],"X-Budibase-Api-Version":["1"],"Cf-Ipcontinent":["NA"],"Cf-Region-Code":["CA"],"Cf-Postal-Code":["90017"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"Cf-Region":["California"],"X-Forwarded-Host":["example.com"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Priority":["u=1, i"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"error":"net/http: HTTP/1.x transport connection broken: http: ContentLength=17 with Body length 0"}

{"level":"error","ts":1727663637.588448,"logger":"http.log.error.log10","msg":"net/http: HTTP/1.x transport connection broken: http: ContentLength=17 with Body length 0","request":{"remote_ip":"172.69.34.119","remote_port":"20932","client_ip":"172.69.34.119","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"Referer":["https://example.com/"],"Priority":["u=1, i"],"Cf-Iplatitude":["34.05150"],"Cf-Ray":["8cb0cfa6de5c525d-LAX"],"X-Budibase-Session-Id":["c1939c4195bb54a0b9f1a52fb548142f8"],"Cookie":["REDACTED"],"Cf-Ipcountry":["US"],"Cf-Iplongitude":["-118.27070"],"Accept-Encoding":["gzip, br"],"X-Budibase-Api-Version":["1"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Site":["same-origin"],"Accept-Language":["zh-CN,zh;q=0.9,en-GB;q=0.8,en;q=0.7,zh-TW;q=0.6"],"Cf-Ipcontinent":["NA"],"Cf-Timezone":["America/Los_Angeles"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"X-Budibase-Type":["client"],"Cf-Region":["California"],"Content-Length":["17"],"X-Forwarded-Proto":["https"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Cdn-Loop":["cloudflare; loops=1"],"Cf-Ipcity":["Los Angeles"],"Cf-Postal-Code":["90017"],"Cf-Region-Code":["CA"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Accept":["application/json"],"Content-Type":["application/json"],"Origin":["https://example.com"],"Sec-Fetch-Dest":["empty"],"Sec-Fetch-Mode":["cors"],"Cf-Metro-Code":["803"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"duration":0.003966148,"status":502,"err_id":"a2qr9mb48","err_trace":"reverseproxy.statusError (reverseproxy.go:1269)"}

{"level":"debug","ts":1727663872.4160943,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_ip":"172.70.211.196","remote_port":"57564","client_ip":"172.70.211.196","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"Cf-Visitor":["{\"scheme\":\"https\"}"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"],"Cf-Ipcontinent":["AS"],"Cf-Iplatitude":["36.79980"],"X-Forwarded-Proto":["https"],"Sec-Fetch-Site":["same-origin"],"Priority":["u=1, i"],"Cookie":["REDACTED"],"Cdn-Loop":["cloudflare; loops=1"],"Cf-Ipcity":["Zibo"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Sec-Ch-Ua-Mobile":["?0"],"X-Budibase-Type":["client"],"Sec-Fetch-Mode":["cors"],"Sec-Fetch-Dest":["empty"],"Referer":["https://example.com/"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"Cf-Iplongitude":["117.96970"],"Origin":["https://example.com"],"Cf-Connecting-Ip":["119.181.224.248"],"Accept-Encoding":["gzip, br"],"X-Forwarded-For":["119.181.224.248"],"Content-Length":["17"],"X-Budibase-Session-Id":["cf88312de49d446878b0f2f88f2664485"],"Accept":["application/json"],"X-Budibase-Api-Version":["1"],"Cf-Ipcountry":["CN"],"Content-Type":["application/json"],"Cf-Ray":["8cb0d56288647c73-LAX"],"Sec-Ch-Ua":["\"Microsoft Edge\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Accept-Language":["zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"method":"POST","uri":"/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0"}

{"level":"debug","ts":1727663872.4190404,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"127.0.0.1:10000","duration":0.000241584,"request":{"remote_ip":"172.70.211.196","remote_port":"57564","client_ip":"172.70.211.196","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"Sec-Ch-Ua":["\"Microsoft Edge\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"X-Forwarded-Proto":["https"],"Sec-Fetch-Mode":["cors"],"Sec-Fetch-Site":["same-origin"],"Referer":["https://example.com/"],"Accept-Encoding":["gzip, br"],"X-Budibase-Api-Version":["1"],"Cf-Ipcontinent":["AS"],"Cf-Iplatitude":["36.79980"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Priority":["u=1, i"],"Content-Length":["17"],"Accept":["application/json"],"Sec-Ch-Ua-Mobile":["?0"],"X-Forwarded-Host":["example.com"],"Cf-Ray":["8cb0d56288647c73-LAX"],"Cf-Timezone":["Asia/Shanghai"],"Cf-Iplongitude":["117.96970"],"X-Forwarded-For":["172.70.211.196"],"Cf-Ipcountry":["CN"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"],"Cookie":["REDACTED"],"Sec-Fetch-Dest":["empty"],"Cdn-Loop":["cloudflare; loops=1"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"Origin":["https://example.com"],"Accept-Language":["zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"],"Cf-Ipcity":["Zibo"],"X-Budibase-Session-Id":["cf88312de49d446878b0f2f88f2664485"],"X-Budibase-Type":["client"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Cf-Connecting-Ip":["119.181.224.248"],"Content-Type":["application/json"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"error":"net/http: HTTP/1.x transport connection broken: http: ContentLength=17 with Body length 0"}

{"level":"error","ts":1727663872.4193215,"logger":"http.log.error.log10","msg":"net/http: HTTP/1.x transport connection broken: http: ContentLength=17 with Body length 0","request":{"remote_ip":"172.70.211.196","remote_port":"57564","client_ip":"172.70.211.196","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"Origin":["https://example.com"],"Cf-Connecting-Ip":["119.181.224.248"],"Accept-Encoding":["gzip, br"],"X-Forwarded-For":["119.181.224.248"],"Content-Length":["17"],"X-Budibase-Session-Id":["cf88312de49d446878b0f2f88f2664485"],"Accept":["application/json"],"X-Budibase-Api-Version":["1"],"Cf-Ipcountry":["CN"],"Content-Type":["application/json"],"Cf-Ray":["8cb0d56288647c73-LAX"],"Sec-Ch-Ua":["\"Microsoft Edge\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Accept-Language":["zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"],"Cf-Ipcontinent":["AS"],"Cf-Iplatitude":["36.79980"],"X-Forwarded-Proto":["https"],"Sec-Fetch-Site":["same-origin"],"Priority":["u=1, i"],"Cookie":["REDACTED"],"Cdn-Loop":["cloudflare; loops=1"],"Cf-Ipcity":["Zibo"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Sec-Ch-Ua-Mobile":["?0"],"X-Budibase-Type":["client"],"Sec-Fetch-Mode":["cors"],"Sec-Fetch-Dest":["empty"],"Referer":["https://example.com/"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"Cf-Iplongitude":["117.96970"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"duration":0.003256967,"status":502,"err_id":"icffz9pnk","err_trace":"reverseproxy.statusError (reverseproxy.go:1269)"}

{"level":"debug","ts":1727664669.3260524,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_ip":"172.70.206.220","remote_port":"10836","client_ip":"172.70.206.220","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"Content-Length":["17"],"Cf-Iplongitude":["119.29060"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"],"Accept":["application/json"],"Origin":["https://example.com"],"X-Budibase-Type":["client"],"Referer":["https://example.com/"],"Priority":["u=1, i"],"Cf-Timezone":["Asia/Shanghai"],"Accept-Encoding":["gzip, br"],"Sec-Ch-Ua-Platform":["\"Windows\""],"X-Budibase-Session-Id":["cd59e437b074548279261848c2f2e245c"],"Accept-Language":["zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"],"Cookie":["REDACTED"],"Cf-Iplatitude":["26.04920"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Sec-Ch-Ua":["\"Microsoft Edge\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Dest":["empty"],"X-Budibase-Api-Version":["1"],"Cf-Connecting-Ip":["112.111.55.253"],"X-Forwarded-For":["112.111.55.253"],"Cf-Ipcity":["Fuzhou"],"Sec-Fetch-Mode":["cors"],"Cdn-Loop":["cloudflare; loops=1"],"Cf-Ipcontinent":["AS"],"Cf-Ipcountry":["CN"],"Cf-Ray":["8cb0e8d73e4208d8-LAX"],"X-Forwarded-Proto":["https"],"Content-Type":["application/json"],"Sec-Fetch-Site":["same-origin"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"method":"POST","uri":"/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0"}

{"level":"debug","ts":1727664669.32811,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"127.0.0.1:10000","duration":0.00018547,"request":{"remote_ip":"172.70.206.220","remote_port":"10836","client_ip":"172.70.206.220","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"Content-Length":["17"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"],"Accept-Language":["zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"],"Content-Type":["application/json"],"Cf-Iplatitude":["26.04920"],"Sec-Fetch-Site":["same-origin"],"Sec-Fetch-Mode":["cors"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"Accept":["application/json"],"Accept-Encoding":["gzip, br"],"Sec-Fetch-Dest":["empty"],"X-Forwarded-For":["172.70.206.220"],"Origin":["https://example.com"],"Cf-Timezone":["Asia/Shanghai"],"Cdn-Loop":["cloudflare; loops=1"],"X-Budibase-Session-Id":["cd59e437b074548279261848c2f2e245c"],"Priority":["u=1, i"],"Sec-Ch-Ua":["\"Microsoft Edge\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Cf-Ipcity":["Fuzhou"],"Cf-Ipcontinent":["AS"],"X-Forwarded-Proto":["https"],"Cf-Iplongitude":["119.29060"],"Sec-Ch-Ua-Platform":["\"Windows\""],"X-Budibase-Type":["client"],"X-Budibase-Api-Version":["1"],"Cf-Connecting-Ip":["112.111.55.253"],"Cf-Ipcountry":["CN"],"Cf-Ray":["8cb0e8d73e4208d8-LAX"],"X-Forwarded-Host":["example.com"],"Referer":["https://example.com/"],"Cookie":["REDACTED"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Sec-Ch-Ua-Mobile":["?0"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"error":"net/http: HTTP/1.x transport connection broken: http: ContentLength=17 with Body length 0"}

{"level":"error","ts":1727664669.3283818,"logger":"http.log.error.log10","msg":"net/http: HTTP/1.x transport connection broken: http: ContentLength=17 with Body length 0","request":{"remote_ip":"172.70.206.220","remote_port":"10836","client_ip":"172.70.206.220","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"Cookie":["REDACTED"],"Cf-Iplatitude":["26.04920"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Sec-Ch-Ua":["\"Microsoft Edge\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Dest":["empty"],"Accept-Language":["zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"],"X-Budibase-Api-Version":["1"],"Cf-Connecting-Ip":["112.111.55.253"],"X-Forwarded-For":["112.111.55.253"],"Cf-Ipcity":["Fuzhou"],"Cdn-Loop":["cloudflare; loops=1"],"Cf-Ipcontinent":["AS"],"Cf-Ipcountry":["CN"],"Cf-Ray":["8cb0e8d73e4208d8-LAX"],"X-Forwarded-Proto":["https"],"Content-Type":["application/json"],"Sec-Fetch-Site":["same-origin"],"Sec-Fetch-Mode":["cors"],"Content-Length":["17"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"],"Accept":["application/json"],"Origin":["https://example.com"],"Cf-Iplongitude":["119.29060"],"Referer":["https://example.com/"],"Priority":["u=1, i"],"Cf-Timezone":["Asia/Shanghai"],"Accept-Encoding":["gzip, br"],"Sec-Ch-Ua-Platform":["\"Windows\""],"X-Budibase-Session-Id":["cd59e437b074548279261848c2f2e245c"],"X-Budibase-Type":["client"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"duration":0.002331108,"status":502,"err_id":"gi41ppvjt","err_trace":"reverseproxy.statusError (reverseproxy.go:1269)"}

{"level":"debug","ts":1727664954.2702355,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_ip":"172.70.91.86","remote_port":"23686","client_ip":"172.70.91.86","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"Cf-Ipcontinent":["AS"],"Cf-Iplatitude":["23.02610"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Referer":["https://example.com/"],"Content-Type":["application/json"],"Cf-Ipcity":["Foshan"],"Accept-Encoding":["gzip, br"],"Sec-Ch-Ua-Platform":["\"Windows\""],"X-Budibase-Session-Id":["cc25879c99df94039a891151a09c5f4c0"],"Cookie":["REDACTED"],"Cf-Connecting-Ip":["14.212.182.118"],"Cf-Ipcountry":["CN"],"X-Forwarded-Proto":["https"],"Accept":["application/json"],"Accept-Language":["en-US,en;q=0.9"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"X-Budibase-Type":["client"],"Cdn-Loop":["cloudflare; loops=1"],"Cf-Iplongitude":["113.13710"],"X-Forwarded-For":["14.212.182.118"],"Cf-Ray":["8cb0efcba9ae419d-LHR"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"Sec-Fetch-Dest":["empty"],"Priority":["u=1, i"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Mode":["cors"],"Origin":["https://example.com"],"Sec-Fetch-Site":["same-origin"],"Cf-Timezone":["Asia/Shanghai"],"Content-Length":["17"],"X-Budibase-Api-Version":["1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"method":"POST","uri":"/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0"}

{"level":"debug","ts":1727664954.2736974,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"127.0.0.1:10000","duration":0.000843758,"request":{"remote_ip":"172.70.91.86","remote_port":"23686","client_ip":"172.70.91.86","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"X-Budibase-Api-Version":["1"],"Referer":["https://example.com/"],"Accept-Encoding":["gzip, br"],"X-Budibase-Session-Id":["cc25879c99df94039a891151a09c5f4c0"],"Cf-Iplongitude":["113.13710"],"Cf-Ray":["8cb0efcba9ae419d-LHR"],"Content-Length":["17"],"Priority":["u=1, i"],"Cf-Ipcontinent":["AS"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Content-Type":["application/json"],"Cookie":["REDACTED"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"X-Forwarded-Host":["example.com"],"Accept-Language":["en-US,en;q=0.9"],"X-Forwarded-Proto":["https"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Sec-Ch-Ua-Mobile":["?0"],"Cf-Connecting-Ip":["14.212.182.118"],"Cf-Ipcountry":["CN"],"X-Budibase-Type":["client"],"Sec-Fetch-Site":["same-origin"],"Cf-Iplatitude":["23.02610"],"Cf-Timezone":["Asia/Shanghai"],"Accept":["application/json"],"Cdn-Loop":["cloudflare; loops=1"],"X-Forwarded-For":["172.70.91.86"],"Cf-Ipcity":["Foshan"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Sec-Fetch-Dest":["empty"],"Sec-Fetch-Mode":["cors"],"Origin":["https://example.com"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"error":"net/http: HTTP/1.x transport connection broken: http: ContentLength=17 with Body length 0"}

{"level":"error","ts":1727664954.2743444,"logger":"http.log.error.log10","msg":"net/http: HTTP/1.x transport connection broken: http: ContentLength=17 with Body length 0","request":{"remote_ip":"172.70.91.86","remote_port":"23686","client_ip":"172.70.91.86","proto":"HTTP/2.0","method":"POST","host":"example.com","uri":"/api/v2/queries/query_datasource_d417999c7d824bb1bb53ba44c212df71_b8485022734c4405bcd476f6d67435a0","headers":{"Cf-Ipcontinent":["AS"],"Cf-Iplatitude":["23.02610"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Referer":["https://example.com/"],"Content-Type":["application/json"],"Cf-Ipcity":["Foshan"],"Accept-Encoding":["gzip, br"],"Sec-Ch-Ua-Platform":["\"Windows\""],"X-Budibase-Session-Id":["cc25879c99df94039a891151a09c5f4c0"],"Cookie":["REDACTED"],"Cf-Connecting-Ip":["14.212.182.118"],"Cf-Ipcountry":["CN"],"X-Forwarded-Proto":["https"],"Accept":["application/json"],"Accept-Language":["en-US,en;q=0.9"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"X-Budibase-Type":["client"],"Cdn-Loop":["cloudflare; loops=1"],"Cf-Iplongitude":["113.13710"],"X-Forwarded-For":["14.212.182.118"],"Cf-Ray":["8cb0efcba9ae419d-LHR"],"X-Budibase-App-Id":["app_79a24f5a85c94e6c94c81448370a144a"],"Sec-Fetch-Dest":["empty"],"Priority":["u=1, i"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Mode":["cors"],"Origin":["https://example.com"],"Sec-Fetch-Site":["same-origin"],"Cf-Timezone":["Asia/Shanghai"],"Content-Length":["17"],"X-Budibase-Api-Version":["1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"duration":0.003897777,"status":502,"err_id":"5xht8vgt4","err_trace":"reverseproxy.statusError (reverseproxy.go:1269)"}

But why are you trying to merge them? What do you expect to gain from doing that? It’s certainly more efficient to route the requests to the correct place using request matchers.

1 Like

Port 8080 is running a restful api service.
Port 10000 is running budibase, which is a low-code development platform that I used to deploy a front-end page that calls a service on port 8080 and has its own /api/* route.
I was using nginx before and did not think too much about merging the two services into /api/* because their /api/* subroutes did not conflict and the requests went through fine.
I now want to use caddy and ran into this problem while migrating the configuration.

Although for the time being this configuration doesn’t meet caddy’s requirements, I’m glad to know the reason for the request error, thank you very much for your help.

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