Caddy reverse-proxy throwing 502 error on POST

I have a Caddy instance running as a reverse proxy to a Go app that presents an http interface (http only, no https)

GET requests work with no problems, e.g. :

curl https://<my_caddy_hostname>:8083/46df8d1574d/ping
pong

But POST requests fail with a 502, e.g.:

curl -v -X POST https://<my_caddy_hostname>:8083/46df8d1574d/foo
-H ‘Content-Type: application/json’
‘{“app”:“test”,“id”:“test”,“data”:{“foo”:“bar”}}’

gives

* We are completely uploaded and fine
* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
< HTTP/2 502
< alt-svc: h3=":443"; ma=2592000
< server: Caddy
< content-length: 0
< date: Tue, 28 Mar 2023 11:20:55 GMT

and on the caddy side…

{"level":"debug","ts":1680002445.846841,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"localhost:49836","total_upstreams":1}
{"level":"debug","ts":1680002455.851198,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"localhost:49836","duration":10.004234974,"request":{"remote_ip":"fdf3:5229:af30:5::","remote_port":"28382","proto":"HTTP/2.0","method":"POST","host":"<my_caddy_hostname>:8083","uri":"/46df8d1574d/foo","headers":{"Accept":["*/*"],"Content-Type":["application/json"],"Content-Length":["109"],"X-Forwarded-For":["fdf3:5229:af30:5::"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["<my_caddy_hostname>:8083"],"User-Agent":["curl/7.86.0"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","server_name":"<my_caddy_hostname>"}},"error":"EOF"}
{"level":"error","ts":1680002455.851816,"logger":"http.log.error","msg":"EOF","request":{"remote_ip":"fdf3:5229:af30:5::","remote_port":"28382","proto":"HTTP/2.0","method":"POST","host":"<my_caddy_hostname>:8083","uri":"/46df8d1574d/foo","headers":{"Accept":["*/*"],"Content-Type":["application/json"],"Content-Length":["109"],"User-Agent":["curl/7.86.0"]},"tls":{"resumed":false,"version":772,"cipher_suite":4867,"proto":"h2","server_name":"<my_caddy_hostname>"}},"duration":10.005012201,"status":502,"err_id":"fivmzbbyg","err_trace":"reverseproxy.statusError (reverseproxy.go:1299)"}

My caddyfile is very simple:

{
  auto_https disable_certs
  persist_config off
  admin :2019
}

:443 {
  header -Server
  tls /ssl/tls.crt /ssl/tls.key
  root * /usr/share/caddy/public
  encode gzip zstd
  php_fastcgi localhost:9000
  reverse_proxy /46df8d1574d/* localhost:49836
  file_server
}

Just to avoid any confusion, this is running on Kubernetes (K3S) so, please remember that references to “localhost” means “containers within the same pod”, which is why the above Caddyfile works (see Pods | Kubernetes)

Please fill out the help topic template, as per the forum rules.

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