title: Serving django with nginx and uWSGI
body: <p>I followed <a href="https://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html" rel="nofollow">this post</a> to serve my django project. The project runs well with <code>manage.py runserver</code> and I want to set it up for production. Here are my setting files:</p>
  
  <p><code>nginx.conf</code>:</p>
  
  <pre><code>upstream django {
      server /tmp/vc.sock;
      #server 10.9.1.137:8002;
  }
  
  server {
      listen      8001;
      server_name 10.9.1.137;
      charset     utf-8;
      client_max_body_size 25M;
  
      location /media  {
          alias /home/deploy/vc/media;
      }
      location /static {
          alias /home/deploy/vc/static;
      }
  
  
      location / {
          uwsgi_pass  django;
          include     /etc/nginx/uwsgi_params;
      }
  }
  </code></pre>
  
  <p><code>uwsgi.ini</code>:</p>
  
  <pre><code>[uwsgi]
  
  chdir           = /home/deploy/vc
  wsgi-file      = vc/wsgi.py
  
  master          = true
  processes       = 2
  #socket          = :8002
  socket          = /tmp/vc.sock
  chmod-socket    = 666
  vacuum          = true
  </code></pre>
  
  <p>If I use TCP port socket (<code>server 10.9.1.137:8002</code> and <code>socket = :8002</code>), it's going to be fine. However if I comment them out and use Unix sockets(<code>server /tmp/vc.sock</code> and <code>socket = /tmp/vc.sock</code>), the server will return 502 error. How should I fix it?</p>
  
  <p><code>EDIT</code> </p>
  
  <p>Here's the nginx error log when I run <code>/etc/init.d/nginx restart</code></p>
  
  <pre><code>nginx: [emerg] invalid host in upstream "/tmp/vc.sock" in /etc/nginx/conf.d/vc.conf:2
  nginx: configuration file /etc/nginx/nginx.conf test failed
  </code></pre>
  
  <p>And this is the warning when I run <code>uwsgi --ini vc/uwsgi.ini</code>:</p>
  
  <pre><code>*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
  </code></pre>
  
  <p>Can't I run uWSGI as root?</p>