title: Nginx proxy on Elastic Beanstalk EC2 instance times out
body: <p>I've got a Docker application up and running on Elastic Beanstalk, and have noticed that occasionally it will time out and return <code>504 Gateway Timeout</code> to requests from the Internet. In order to debug this, I created a script that I'm running on my local machine that constantly sends the exact same request to my application and tells me if it received anything but a  <code>200</code> response. This is an extract of the output:</p>
  
  <pre><code>[21:38:14] Success
  [21:38:15] Success
  [21:38:15] Success
  [21:39:15] Non 200 code: 504
  [21:40:15] Non 200 code: 504
  [21:41:15] Non 200 code: 504
  [21:42:15] Non 200 code: 504
  [21:43:15] Non 200 code: 504
  [21:44:15] Success
  [21:44:15] Success
  [21:44:16] Success
  </code></pre>
  
  <p>I was wondering if the <code>504</code> requests even hit my EC2 instance, so I checked its nginx logs:</p>
  
  <pre><code>172.31.8.21 - [01/Mar/2015:21:38:15 +0000] "GET /v1/jobs HTTP/1.1" 200 5
  172.31.8.21 - [01/Mar/2015:21:38:15 +0000] "GET /v1/jobs HTTP/1.1" 200 5
  172.31.8.21 - [01/Mar/2015:21:38:15 +0000] "GET /v1/jobs HTTP/1.1" 200 5
  172.31.23.11 - [01/Mar/2015:21:39:15 +0000] "GET /v1/jobs HTTP/1.1" 400 0
  172.31.23.11 - [01/Mar/2015:21:40:15 +0000] "GET /v1/jobs HTTP/1.1" 400 0
  172.31.23.11 - [01/Mar/2015:21:41:15 +0000] "GET /v1/jobs HTTP/1.1" 400 0
  172.31.23.11 - [01/Mar/2015:21:42:15 +0000] "GET /v1/jobs HTTP/1.1" 400 0
  172.31.23.11 - [01/Mar/2015:21:43:15 +0000] "GET /v1/jobs HTTP/1.1" 400 0
  </code></pre>
  
  <p>Looking at the logs, it seems that the load balancer sends a request to my EC2 instance, which then times out after 60 seconds which makes the load balancer return <code>504</code> and logs <code>400</code> into my nginx logs. What's really strange is that the IP address of the <code>504</code> requests is different from the IP address of every other successful request.</p>
  
  <p>As I understand it, this is the topology of how a request is handled in a Docker Elastic Beanstalk application:</p>
  
  <pre><code>request -&gt; load balancer -&gt; load balancer proxy -&gt; EC2 instance -&gt; EC2 instance proxy -&gt; Docker image
  </code></pre>
  
  <p>So I checked the nginx logs inside my Docker image, and there are no <code>access.log</code> entries for the time period when the load balancer was returning <code>504</code>s.</p>
  
  <p>That means that for some reason, requests are getting to the EC2 instance proxy and then timing out. Has anybody experienced this problem and knows why? I'd also like to know why the timeouts only happen when the <code>172.31.23.11</code> IP address is the one doing the requesting.</p>
  
  <p>It's also worth noting that nginx on my EC2 instance reports nothing in its <code>error.log</code> when the timeouts occur.</p>