Issues with setting up Grpc in Caddy Config

1. Caddy version (caddy version): Caddy:2.4.6-alpine

2. How I run Caddy:

a. System environment:

b. Command:

Paste command here.

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

    cloudname-develop.westeurope.azurecontainer.io {
        handle_path /service1/* {
            reverse_proxy localhost:8080
        }
    
        handle_path /service2/* {
            reverse_proxy h2c://localhost:8081
        }
    
        handle_path /service3/* {
            reverse_proxy localhost:8082
        }
    }

3. The problem I’m having:

I am trying to setup up Caddy to reverse proxy to our GRPC service that is run in docker, at localhost:8081.

When ever I try to hit the service we get a unexpected EOF error in the Caddy log and nothing comes through the service.

4. Error messages and/or full log output:


{
  "level": "error",
  "ts": 1641972868.5600731,
  "logger": "http.log.error",
  "msg": "unexpected EOF",
  "request": {
    "remote_addr": "1.241.232.10:15234",
    "proto": "HTTP/2.0",
    "method": "POST",
    "host": "cloudname-develop.westeurope.azurecontainer.io",
    "uri": "/dataStreaming.DataStreaming/PausePlayer",
    "headers": {
      "X-Grpc-Web": [
        "1"
      ],
      "Content-Type": [
        "application/grpc-web-text"
      ],
      "Sec-Fetch-Site": [
        "cross-site"
      ],
      "Accept-Encoding": [
        "gzip, deflate, br"
      ],
      "Accept-Language": [
        "en-US"
      ],
      "X-User-Agent": [
        "grpc-web-javascript/0.1"
      ],
      "Accept": [
        "application/grpc-web-text"
      ],
      "Origin": [
        "file://"
      ],
      "User-Agent": [
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) bloom-rpc-client/1.5.3 Chrome/78.0.3904.130 Electron/7.1.11 Safari/537.36"
      ],
      "Sec-Fetch-Mode": [
        "cors"
      ],
      "Content-Length": [
        "8"
      ]
    },
    "tls": {
      "resumed": false,
      "version": 772,
      "cipher_suite": 4865,
      "proto": "h2",
      "proto_mutual": true,
      "server_name": "cloudname-develop.westeurope.azurecontainer.io"
    }
  },
  "duration": 0.003767059,
  "status": 502,
  "err_id": "ctn3v34jc",
  "err_trace": "reverseproxy.statusError (reverseproxy.go:886)"
}

5. What I already tried:

I tried doing it this way as well just for a test without needing specify the service name. Same issue

cloudname-develop.westeurope.azurecontainer.io {    
         reverse_proxy h2c://localhost:8081
}

6. Links to relevant resources:

Sounds like you’re running in Docker. Are you sure localhost will reach that service? Proxying to localhost will typically only reach servers running inside the same container (unless you use the host networking mode).

Turn on debug mode by adding this at the top of your Caddyfile, then check your logs again. It’ll probably show a more detailed message:

{
	debug
}
1 Like

Thank you for you help :slightly_smiling_face:. We resolved our issue, there was an issue in our service

What was the issue exactly, in case someone else runs into this thread with the same problem?

1 Like