title: Rails app on AWS Elastic Beanstalk: Bad nginx config
body: <p>So I have a rails application that I built and deployed via AWS Elastic Beanstalk a few months ago. The project was put on hold so I terminated the environment, expecting to be able to re-deploy when we returned to this project.</p>
  
  <p>Despite my app still running just fine on my local dev environment, I cannot get it to deploy. The error from my <code>eb-activty.log</code>: </p>
  
  <pre><code>PG::ConnectionBad: could not connect to server: No such file or directory
      Is the server running locally and accepting
      connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
  </code></pre>
  
  <p>The database is a standalone AWS RDS instance that I can successfully test the connection to, so I know its running. I have added the requisite environment variables and configured my <code>database.yml</code> accordingly. To be clear, this is an application that used to work. I hadn't made any changes between the time I terminated the environment and when I went to re-deploy.</p>
  
  <p>The root problem seems to be that nginx isn't being configured properly, as trying to access the server returns:</p>
  
  <pre><code>502 Bad Gateway
  nginx/1.12.1
  </code></pre>
  
  <p>and when I check the nginx <code>error.log</code> its filled with errrors like this:</p>
  
  <pre><code>2018/09/19 14:12:35 [crit] 3069#0: *653 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.47.147, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/", host: "172.31.47.147"
  </code></pre>
  
  <p>Naturally, I googled my error, and found <a href="https://stackoverflow.com/questions/30355569/rails-application-deployed-on-elastic-beanstalk-with-puma-fails-502-errors-on">this stackoverflow post.</a></p>
  
  <p>I've tried adding these suggested lines from the top-rated answer to my <code>puma.rb</code></p>
  
  <pre><code>bind "unix:///var/run/puma/my_app.sock"
  pidfile "/var/run/puma/my_app.sock"
  </code></pre>
  
  <p>Which caused no change at all.</p>
  
  <p>I made sure to try the other suggestions, including having a direct look at the nginx configuration file. I did find that there's no upstream set up in the config. As best as I can see, the nginx aspect of the deployment pipeline is automated by Elastic Beanstalk so clearly something else I've set must be incorrect. </p>
  
  <p>I've found that under no circumstances can I get the app to deploy using <code>eb deploy</code> I can only make changes by creating a new environment each time. I've recreated the app countless time, experimenting with different settings, versions of gems and packages, different ruby versions...etc. All in all, I still can't affect change on the error, I can't even get a new error! just the same <code>PG:ConnectionBad</code> or <code>502 bad gateway</code> depending on if I look from console or browser. </p>
  
  <p>From my googling I've come under the impression that this is related to puma in some regard but puma is a bit of a black box for me.</p>
  
  <p>I'm feeling pretty lost here, I'd really appreciate any guidance you'd be willing to share. Feel free to ask for more info from any log or file, I'm happy to provide more detail. Thanks in advance!</p>