Empty response with :alpine

Using caddy via docker with :alpine tag

Caddy is returning an empty 200 response from network requests. To check if it was a permission problem, I’ve swapped Caddy from port 80 on the host to 8080. I also directly exposed the web container as port 80. It responds correctly. I’ve removed and simplified my caddy json to the point that nothing else is there and it is only working in http mode. No joy

Network requests give no log output from Caddy, but the http response has Caddy headers.

Oddly, if I curl from the docker host via localhost, Caddy reverse proxy works as expected.

Any ideas? Various command results and logs below:

$ curl --include http://ip-172-31-61-149.ec2.internal:80/_health/

HTTP/1.1 200 OK
Server: gunicorn/20.0.4
Date: Fri, 03 Apr 2020 13:56:16 GMT
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

7862

$ curl --include http://ip-172-31-61-149.ec2.internal:8080/_health/

HTTP/1.1 200 OK
Server: Caddy
Date: Fri, 03 Apr 2020 13:56:59 GMT
Content-Length: 0

Caddy json:

{
    "apps": {
        "http": {
            "http_port": 80,
            "servers": {
                "srv0": {
                    "listen": [
                        ":80"
                    ],
                    "routes": [
                        {
                            "match": [
                                {
                                    "host": [
                                        "*"
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "handler": "reverse_proxy",
                                    "upstreams": [
                                        {
                                            "dial": "web:5000"
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
        }
    },
    "logging": {
        "logs": {
            "default": {
                "level": "DEBUG"
            }
        }
    }
}

port 80 on the host maps to web container port 5000
port 8080 on the host maps to caddy container port 80

No logs from caddy here:

$ sudo docker logs bf61 --follow

{"level":"info","ts":1585921124.2905886,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile.json","config_adapter":""}
{"level":"info","ts":1585921128.296021,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["localhost:2019"]}
2020/04/03 13:38:48 [INFO][cache:0xc0003d8b40] Started certificate maintenance routine
{"level":"info","ts":1585921128.3014855,"logger":"http","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
{"level":"info","ts":1585921128.3026268,"logger":"tls","msg":"cleaned up storage units"}
{"level":"debug","ts":1585921128.3027163,"logger":"http","msg":"starting server loop","address":":80","http3":false,"tls":false}
{"level":"info","ts":1585921128.3028102,"msg":"autosaved config","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1585921128.3028185,"msg":"serving initial configuration"}

If I make the request from the docker host,

[ec2-user@ip-172-31-61-149 ~]$ curl http://localhost:8080/_health/
7862

With headers:

[ec2-user@ip-172-31-61-149 ~]$ curl --include http://localhost:8080/_health/
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Fri, 03 Apr 2020 14:01:32 GMT
Server: Caddy
Server: gunicorn/20.0.4
Content-Length: 4

7862

Logs

[ec2-user@ip-172-31-61-149 sudo docker logs bf61
{"level":"info","ts":1585921124.2905886,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile.json","config_adapter":""}
{"level":"info","ts":1585921128.296021,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["localhost:2019"]}
2020/04/03 13:38:48 [INFO][cache:0xc0003d8b40] Started certificate maintenance routine
{"level":"info","ts":1585921128.3014855,"logger":"http","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
{"level":"info","ts":1585921128.3026268,"logger":"tls","msg":"cleaned up storage units"}
{"level":"debug","ts":1585921128.3027163,"logger":"http","msg":"starting server loop","address":":80","http3":false,"tls":false}
{"level":"info","ts":1585921128.3028102,"msg":"autosaved config","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1585921128.3028185,"msg":"serving initial configuration"}
{"level":"debug","ts":1585922480.6439543,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","request":{"method":"GET","uri":"/_health/","proto":"HTTP/1.1","remote_addr":"172.17.0.1:38064","host":"localhost:8080","headers":{"X-Forwarded-For":["172.17.0.1"],"User-Agent":["curl/7.61.1"],"Accept":["*/*"]}},"headers":{"Content-Type":["text/html; charset=utf-8"],"Server":["gunicorn/20.0.4"],"Date":["Fri, 03 Apr 2020 14:01:20 GMT"]},"duration":4.01261915,"status":200}
{"level":"debug","ts":1585922492.832654,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","request":{"method":"GET","uri":"/_health/","proto":"HTTP/1.1","remote_addr":"172.17.0.1:38078","host":"localhost:8080","headers":{"X-Forwarded-For":["172.17.0.1"],"User-Agent":["curl/7.61.1"],"Accept":["*/*"]}},"headers":{"Server":["gunicorn/20.0.4"],"Date":["Fri, 03 Apr 2020 14:01:32 GMT"],"Content-Type":["text/html; charset=utf-8"]},"duration":4.004468968,"status":200}
[ec2-user@ip-172-31-61-149 ~]$

The host matcher of * is probably your problem. From the docs:

Wildcards ( * ) may be used to represent exactly one label of the hostname, in accordance with RFC 1034 (because host matchers are also used for automatic HTTPS which influences TLS certificates). Thus, a host of * matches hosts like localhost or internal but not example.com . To catch all hosts, omit the host matcher entirely.

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