我们的nginx报错如下:
2017/10/19 10:47:40 [crit] 41689#0: *23414459 connect() to 127.0.0.1:1234 failed (99: Cannot assign requested address) while connecting to upstream, client: 10.0.0.1, server: example.com, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:1234/", host: "www.example.com"
这意味着 nginx 在尝试连接上游时无法请求本地端口。但我发现当所有ip的本地端口用完时就会出现这个问题。检查如下:
Thu Oct 19 10:47:40 CST 2017
54997 <- system wide local ports used. 54997 is the max for my server, here nginx begin reporting errors
22.140.119.4 44543 <- local ports used for public ip
127.0.0.1 19978 <- local ports used for 127.0.0.1
所以我的问题是为什么分配失败,因为只有 19978 个本地端口用于环回 ip?
系统信息
nginx: openresty/1.11.2.1
kernel: Linux 4.9
distro: Ubuntu 14.04