Ruby on rails 如何使用Nginx+避免502坏网关;轨道&x2B;独角兽

Ruby on rails 如何使用Nginx+避免502坏网关;轨道&x2B;独角兽,ruby-on-rails,nginx,unicorn,Ruby On Rails,Nginx,Unicorn,我每天都有相同的502个错误,但找不到原因 2014/12/22 16:33:03 [error] 1697#0: *331 upstream prematurely closed connection while reading response header from upstream, client: 105.121.243.92, server: server01.domain.com, request: "GET /doco/in_documents HTTP/1.0", upstre

我每天都有相同的502个错误,但找不到原因

2014/12/22 16:33:03 [error] 1697#0: *331 upstream prematurely closed connection while reading response header from upstream, client: 105.121.243.92, server: server01.domain.com, request: "GET /doco/in_documents HTTP/1.0", upstream: "http://unix:/tmp/unicorn.docs.sock:/doco/in_documents", host: "go.domain.com:443"
2014/12/22 16:33:05 [error] 1697#0: *331 connect() failed (111: Connection refused) while connecting to upstream, client: 105.121.243.92, server: server01.domain.com, request: "GET /doco/in_documents HTTP/1.0", upstream: "http://10.213.0.46:80/doco/in_documents", host: "go.domain.com:443"
2014/12/22 16:33:09 [error] 1697#0: *334 upstream prematurely closed connection while reading response header from upstream, client: 10.212.255.3, server: server01.domain.com, request: "GET /doco/in_documents HTTP/1.1", upstream: "http://unix:/tmp/unicorn.docs.sock:/doco/in_documents", host: "server01.domain.com"
2014/12/22 16:33:09 [error] 1697#0: *334 connect() failed (111: Connection refused) while connecting to upstream, client: 10.212.255.3, server: server01.domain.com, request: "GET /doco/in_documents HTTP/1.1", upstream: "http://10.213.0.46:80/doco/in_documents", host: "server01.domain.com"
2014/12/22 16:33:15 [info] 1697#0: *333 client closed connection while waiting for request, client: 10.212.255.3, server: 0.0.0.0:80
2014/12/22 16:33:15 [info] 1697#0: *335 client closed connection while waiting for request, client: 10.212.255.3, server: 0.0.0.0:80
2014/12/22 16:33:15 [info] 1697#0: *336 client closed connection while waiting for request, client: 10.212.255.3, server: 0.0.0.0:80
2014/12/22 16:33:15 [info] 1697#0: *338 client closed connection while waiting for request, client: 10.212.255.3, server: 0.0.0.0:80
2014/12/22 16:33:15 [info] 1697#0: *337 client closed connection while waiting for request, client: 10.212.255.3, server: 0.0.0.0:80
2014/12/22 16:33:17 [info] 1697#0: *334 epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while sending request to upstream, client: 10.212.255.3, server: server01.domain.com, request: "GET /doco/in_documents HTTP/1.1", upstream: "http://unix:/tmp/unicorn.docs.sock:/doco/in_documents", host: "server01.domain.com"
2014/12/22 16:33:19 [info] 1698#0: *343 epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while sending request to upstream, client: 105.121.243.92, server: server01.domain.com, request: "GET /doco/in_documents HTTP/1.0", upstream: "http://unix:/tmp/unicorn.docs.sock:/doco/in_documents", host: "go.domain.com:443"
2014/12/22 16:33:35 [info] 1698#0: *347 client closed connection while waiting for request, client: 10.212.255.3, server: 0.0.0.0:80
2014/12/22 16:33:35 [info] 1698#0: *346 client closed connection while waiting for request, client: 10.212.255.3, server: 0.0.0.0:80

有没有办法避免这种情况?我尝试了不同于其他问题的方法,但没有效果。

根据您的错误日志和返回的状态(502),有一点是肯定的,您的上游服务器没有返回响应。我建议您检查上游配置、地址、端口或其他信息。

您可以发布vhost文件和unicorn配置文件吗?