Did you've find a solution for this problem?
We're facing probably a similiar problem, where the apache backend is running fine for some hours and then nginx get 504 error from time to time, with an exact time difference of 1/3/5/9 minutes, the the backends run fine again for 1-2-3 hours.
The upstream is an Centos7/Apache2.4/PHP 5.6 cluster and there in absolutely no load on nginx and the upstreams, maxium 1 client from time to time. Both backend servers shows these problems, with an Apache running on windows this problem has never been occured.
I'm pretty sure it's not directly an nignx issue but after days of researching I have no idea what to try next.....
2016/05/22 11:33:55 [notice] 4904#6056: using sockapi from "4;"
2016/05/22 11:33:55 [notice] 4268#5176: sockinit() attempting to access sockapi
2016/05/22 11:33:55 [notice] 4268#5176: Access to sockapi succeded!
2016/05/22 11:33:55 [notice] 4268#5176: using sockapi from "4;"
2016/05/22 11:33:55 [notice] 2396#1404: sockinit() attempting to access sockapi
2016/05/22 11:33:55 [notice] 2396#1404: Access to sockapi succeded!
2016/05/22 11:33:55 [notice] 2396#1404: using sockapi from "4;"
2016/05/22 13:03:11 [warn] 5884#1340: *1770011 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:03:11 [error] 5884#1340: *1770011 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:06:11 [warn] 2292#5648: *1770018 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:06:11 [error] 2292#5648: *1770018 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:17:11 [warn] 4268#6072: *1770041 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.14:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:17:11 [error] 4268#6072: *1770041 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.14:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:18:11 [warn] 4268#6072: *1770044 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:18:11 [error] 4268#6072: *1770044 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:19:11 [warn] 5884#1340: *1770048 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.14:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:19:11 [error] 5884#1340: *1770048 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.14:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:21:11 [warn] 5884#1340: *1770053 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.14:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:21:11 [error] 5884#1340: *1770053 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.14:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:22:11 [warn] 6088#540: *1770056 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:22:11 [error] 6088#540: *1770056 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:43:11 [warn] 592#5524: *1770100 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:43:11 [error] 592#5524: *1770100 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:45:11 [warn] 4996#2736: *1770105 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:45:11 [error] 4996#2736: *1770105 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:51:11 [warn] 1768#5656: *1770145 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:51:11 [error] 1768#5656: *1770145 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:56:11 [warn] 1812#4888: *1770156 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 13:56:11 [error] 1812#4888: *1770156 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 14:16:11 [warn] 4268#6072: *1770198 upstream server temporarily disabled while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"
2016/05/22 14:16:11 [error] 4268#6072: *1770198 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 69.162.124.236, server: wahl2.hannover-stadt.de, request: "HEAD / HTTP/1.1", upstream: "http://192.168.57.88:80/wrs/", host: "wahl2.hannover-stadt.de"