Docker nginx 服务不接受连接,而单个副本接受连接



我的docker swarm有一个API服务,它使用Nginx代理来访问报告服务。Nginx 代理只做proxy_pass并在 2 个副本中运行。我在通过服务名称或服务 IP 访问 Nginx 代理时遇到问题。有时它有效,但主要是我得到这个响应:

# curl 'http://nginx-proxy:8000/v1/report?id=662867'
curl: (7) Couldn't connect to server
# curl 'http://10.0.17.13:8000/v1/report?id=662867'
curl: (7) Couldn't connect to server

另一方面,如果我通过 IP 或从外部 docker 网络访问单个副本 - 它工作得很好:

# curl 'http://10.0.17.14:8000/v1/report?id=662867'
0   662867  0   10  6   6   0.0 194 3   5   437
# curl 'http://10.0.17.18:8000/v1/report?id=662867'
0   662867  0   10  6   6   0.0 194 3   5   437

感觉内部 docker 平衡器被请求量淹没并停止接受新连接。nginx日志中没有错误 - 每个请求的状态为200。但 API 日志显示了这一点:

INFO Cannot get online report: Get http://nginx-proxy:8000/v1/report?id=732743: dial tcp 10.0.17.13:8000: connect: cannot assign requested address caller=/go/src/api/src/reader.go:300 (*ReaderCursor).readOnline
INFO Cannot get online report: Get http://nginx-proxy:8000/v1/report?id=732703: dial tcp 10.0.17.13:8000: connect: cannot assign requested address caller=/go/src/api/src/reader.go:300 (*ReaderCursor).readOnline

我使用的是官方 Nginx 图像,仅将worker_processes auto;从 1 修改为自动。

任何想法可能出错或在哪里寻找?

问题根本不在docker中。它在一个 API 代码中,该代码运行多个进程,每个帖子默认 2 个连接。许多请求用完了用于客户端连接的所有本地端口。

修复了http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = 100问题

最新更新