title: Error with Nginx/Gunicorn connect() to .sock failed (111: Connection refused) while connecting to upstream
body: <p>I have done endless searching and attempts at fixing this issue, but this refuses to work. </p>
  
  <p>Im using <code>Python 3.3/Gunicorn/Nginx</code>, when I try to run my site I get:</p>
  
  <pre><code>[error] 904#0: *1 connect() to unix:/home/user/project/project.sock failed (111: Connection refused) while connecting to upstream, client: , server: mysite.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/home/user/project/project.sock:/favicon.ico", host: "mysite.com", referrer: "mysite.com/"
  </code></pre>
  
  <p>I was following <a href="https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-14-04" rel="nofollow">this article</a> completely, after several attempts of reattempting it all I am still receiving this error.</p>
  
  <p>Here is what my configs look like:
  <strong>upstart script in <code>/etc/init</code></strong></p>
  
  <pre><code>description "Gunicorn application server running myproject"
  
      start on runlevel [2345]
      stop on runlevel [!2345]
  
      respawn          #respawn this on reboot
      setuid user        #set as unix user 'jd' to run as
      setgid www-data  #user used by nginx
  
      env PATH=/home/user/project/projectenv/bin
      chdir /home/user/project
      exec gunicorn --workers 3 --bind unix:project.sock -m 007 wsgi
  </code></pre>
  
  <p>the permissions on this file:</p>
  
  <pre><code>    chmod 644
      user user 373 Dec 13 09:21 homepage.conf
  </code></pre>
  
  <p>**nginx </p>
  
  <pre><code>config**
      server {
          listen 80;
  
          server_name mysite.com;
  
          error_log /home/user/project/nginx_error.log info;
  
          root /home/user/project/projectenv;
  
          location / {
              include proxy_params;
              proxy_pass http://unix:/home/user/project/project.sock;
          }
  
      }
  </code></pre>
  
  <p>if i run <code>nginx -t</code> in the directory of the nginx config, it shows:</p>
  
  <pre><code>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
  </code></pre>
  
  <p><strong>permissions of <code>/home/user/project/project.sock;</code></strong></p>
  
  <pre><code>srwxrwx--- 1 user www-data 
  </code></pre>
  
  <p><strong>my <code>wsgi.py</code> file</strong> (as outlined in the article) contains:</p>
  
  <pre><code>from homepage import application
  
  if __name__ == "__main__":
      application.run()
  </code></pre>
  
  <p>The interesting thing is, if I try out this command:</p>
  
  <pre><code>gunicorn --bind 0.0.0.0:8000 wsgi
  </code></pre>
  
  <p>outlined <a href="https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-14-04#testing-gunicorn-39-s-ability-to-serve-the-project" rel="nofollow">here</a></p>
  
  <p>Gunicorn starts up fine, and I can view my page perfectly.</p>
  
  <p>The real question is, what is the issue causing this to not run from an <code>ubuntu startup script</code> in <code>/etc/init</code>? ... because the script is running fin</p>
  
  <p>Does anyone see anything?</p>
  
  <p>Thank you.       </p>