【问题标题】:Caddy proxy in docker gives empty responsedocker中的Caddy代理给出空响应
【发布时间】:2018-06-06 12:37:15
【问题描述】:

我有一个运行 Caddy 的 docker 容器和另一个 Web 服务器。

在我的Dockerfile 我有

EXPOSE 80 10240   # 10240 is the port of the other webserver.

我是这样运行 docker 的(不要问我为什么需要 EXPOSE -p)。

docker run -p 80:80 -p 10240:1024 -it <hash>

这将启动两个服务器。在我的主机上(它是 Mac 顺便说一句)我可以连接到 localhost:10240 很好。但是,如果我连接到 localhost:80,我会得到一个空响应(断开连接)。

docker 容器中的 Netstat 显示:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:10240           0.0.0.0:*               LISTEN      19/node         
tcp6       0      0 :::80                   :::*                    LISTEN      9/caddy         

这就是它开始变得奇怪的地方。如果我 curl -L localhost docker 容器内,它工作正常 - 我从 10240 服务器获取网页。

如果我在 docker 容器中 curl -L 127.0.0.1,它会返回 404 Site 127.0.0.1 is not served on this interface。好吧好吧。

如果我在外部容器中curl -L 127.0.0.1,它返回404 Site 127.0.0.1 is not served on this interface。所以不知何故,我的请求通过了,但 Caddy 丢弃了来自容器外部的 localhost 请求,而不是来自容器内部。我启用了日志记录,但它什么也没打印。

谁能告诉我到底发生了什么?所有这些 docker 端口转发的东西都是荒谬的。

这是我的 Caddyfile(我已经尝试了大约 10 亿个 localhost127.0.0.1 等的其他组合):

localhost:80
bind 0.0.0.0
proxy / 127.0.0.1:10240

【问题讨论】:

  • 这是一个错字“docker run -p 80:80 -p 10240:1024 -it ”吗?这样,您将发布端口 1024 而不是 10240...
  • 啊,是的,这是一个错字。我实际上确实使用了 10240。

标签: docker caddy caddyfile


【解决方案1】:

我不确定,但我怀疑这是因为 Docker for Mac 的网络是 kind of broken。我放弃了 Caddy 并尝试用 Traefik 做同样的想法,没有工作(尽管它给出了“网关错误”而不是完全断开连接)。

将所有内容移至 Linux 后,它就可以完美运行。

【讨论】:

    猜你喜欢
    • 2021-05-09
    • 2017-12-31
    • 2018-12-29
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    • 2012-08-28
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多