title: Error 104: Connection reset by peer in Nginx using Node js
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>2016/08/18 18:15:28 [error] 19201#0: *38 upstream prematurely closed connection while reading response header from upstream, client: 116.36.170.142, server: , request: "POST /adm/contents/insert HTTP/1.1", upstream: "http://127.0.0.1:8081/adm/contents/insert", host: "cidermics.com", referrer: "http://cidermics.com/adm/contents/insert"
  2016/08/18 18:15:28 [error] 19201#0: *38 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 116.36.170.142, server: , request: "POST /adm/contents/insert HTTP/1.1", upstream: "http://127.0.0.1:8081/adm/contents/insert", host: "cidermics.com", referrer: "http://cidermics.com/adm/contents/insert"</code></pre>
  </div>
  </div>
  </p>
  
  <p>104: Connection reset by peer</p>
  
  <p>It's an error When I insert some contents in Nginx AWS Elastic Beanstalk.</p>
  
  <p>(But I can insert it in localhost server when I upload same things.)</p>
  
  <p>502 Bad Gateway nginx/1.8.1</p>
  
  <p>The important thing is I can insert it when the short codes in sql server(but sometimes I can't insert even short codes if it include bold tag or color font etc),</p>
  
  <p>But if I insert it when It long codes, It can't upload.</p>
  
  <p>(even It can insert in localhost.)</p>
  
  <p>I think the problem is Nginx or SQL.</p>
  
  <p>I used to have an nginx too large entity error so I put the "client_max_body_size size;".</p>
  
  <p>AWS error logs codes</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>/var/app/current/node_modules/mysql/lib/protocol/Parser.js:77
          throw err; // Rethrow non-MySQL errors
          ^
  
  Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1
      at Query.Sequence._packetToError (/var/app/current/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
      at Query.ErrorPacket (/var/app/current/node_modules/mysql/lib/protocol/sequences/Query.js:83:18)
      at Protocol._parsePacket (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:280:23)
      at Parser.write (/var/app/current/node_modules/mysql/lib/protocol/Parser.js:73:12)
      at Protocol.write (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:39:16)
      at Socket.&lt;anonymous&gt; (/var/app/current/node_modules/mysql/lib/Connection.js:98:28)
      at emitOne (events.js:77:13)
      at Socket.emit (events.js:169:7)
      at readableAddChunk (_stream_readable.js:153:18)
      at Socket.Readable.push (_stream_readable.js:111:10)
      at TCP.onread (net.js:531:20)
      --------------------
      at Protocol._enqueue (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:141:48)
      at PoolConnection.query (/var/app/current/node_modules/mysql/lib/Connection.js:203:25)
      at /var/app/current/routes/model/mysql.js:28:14
      at Ping.onOperationComplete [as _callback] (/var/app/current/node_modules/mysql/lib/Pool.js:101:5)
      at Ping.Sequence.end (/var/app/current/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
      at Ping.Sequence.OkPacket (/var/app/current/node_modules/mysql/lib/protocol/sequences/Sequence.js:105:8)
      at Protocol._parsePacket (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:280:23)
      at Parser.write (/var/app/current/node_modules/mysql/lib/protocol/Parser.js:73:12)
      at Protocol.write (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:39:16)
      at Socket.&lt;anonymous&gt; (/var/app/current/node_modules/mysql/lib/Connection.js:98:28)</code></pre>
  </div>
  </div>
  </p>
  
  <p>proxy.conf</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code># Elastic Beanstalk Managed
  
  # Elastic Beanstalk managed configuration file
  # Some configuration of nginx can be by placing files in /etc/nginx/conf.d
  # using Configuration Files.
  # http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/customize-containers.html 
  # 
  # Modifications of nginx.conf can be performed using container_commands to modify the staged version
  # located in /tmp/deployment/config/etc#nginx#nginx.conf
   
  upstream nodejs {
      server 127.0.0.1:8081;
      keepalive 256;
  }
  
  server {
   
   client_max_body_size 3000M;
      listen 80;
      if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
          set $year $1;
          set $month $2;
          set $day $3;
          set $hour $4; 
      }
      access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
      access_log  /var/log/nginx/access.log  main;
   
   
  
      location / {
       client_max_body_size 3000M;
          proxy_pass  http://nodejs;
          proxy_set_header   Connection "";
          proxy_http_version 1.1;  
          proxy_set_header        Host            $host;
          proxy_set_header        X-Real-IP       $remote_addr;
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
          
         
      }
  gzip on;
  gzip_comp_level 4;
  gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
   
      
  }</code></pre>
  </div>
  </div>
  </p>