title: uWSGI + nginx for django project, error with strting uwsgi
body: <p>I try to up webserver for django on nginx+uwsgi, os - debian (3.1.0-1-amd64 x86_64)
  nginx 1.1.8-1, uwsgi 0.9.8.3-1
  configuration:</p>
  
  <pre><code>&lt;uwsgi&gt;
  &lt;socket&gt;/tmp/uwsgi.sock&lt;/socket&gt;
  &lt;process&gt;1&lt;/process&gt;
  &lt;master/&gt;
  &lt;enable-threads/&gt;
  &lt;uid&gt;33&lt;/uid&gt;
  &lt;gid&gt;33&lt;/gid&gt;
  &lt;pidfile&gt;/tmp/uwsgi.pid&lt;/pidfile&gt;
  &lt;/uwsgi&gt;
  </code></pre>
  
  <p>in file /etc/uwsgi/apps-enabled/webapp.xml
  nginx configuration</p>
  
  <pre><code>location / {
          uwsgi_pass unix:///tmp/uwsgi.sock;
          include uwsgi_params;
          uwsgi_param UWSGI_SCRIPT webapp;
          uwsgi_param UWSGI_CHDIR  /data/web/webapp/webapp;
      }
  </code></pre>
  
  <p>all projet in /data/web/webapp/webapp/, here setting.py, urls ect.
  in /data/web/webapp/webapp/webapp.py </p>
  
  <pre><code>import sys, os
  import django.core.handlers.wsgi
  sys.path.insert(0, '/data/web/webapp/webapp')
  os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
  application = django.core.handlers.wsgi.WSGIHandler()
  </code></pre>
  
  <p>uid and gid 33 it is www-data user
  try run uwsgi as</p>
  
  <blockquote>
    <p>root#uwsgi -s /var/run/uwsgi.sock -x
    /etc/uwsgi/apps-enabled/webapp.xml</p>
  </blockquote>
  
  <pre><code>[uWSGI] parsing config file /etc/uwsgi/apps-enabled/webapp.xml
  *** Starting uWSGI 0.9.8.3-debian (64bit) on [Wed Dec 14 21:42:02 2011] ***
  compiled with version: 4.6.1 on 27 July 2011 18:25:51
  writing pidfile to /tmp/uwsgi.pid
  uWSGI running as root, you can use --uid/--gid/--chroot options
  setgid() to 33
  setuid() to 33
  your memory page size is 4096 bytes
  unlink(): Permission denied [socket.c line 38]
  bind(): Address already in use [socket.c line 70]
  </code></pre>
  
  <p>how permission they want? and what's the problem..
  if i run uwsgi as root error is gone, and i see </p>
  
  <pre><code> *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
  your memory page size is 4096 bytes
  uwsgi socket 0 bound to UNIX address /var/run/uwsgi.sock fd 3
  uwsgi socket 1 bound to UNIX address /tmp/uwsgi.sock fd 4
  your server socket listen backlog is limited to 100 connections
  *** Operational MODE: single process ***
  *** no app loaded. going in full dynamic mode ***
  *** uWSGI is running in multiple interpreter mode ***
  spawned uWSGI master process (pid: 20732)
  spawned uWSGI worker 1 (pid: 20733, cores: 1)
  </code></pre>
  
  <p>but when i try to access the server, ngix returns 502 error page. And more: permission error in nginx logs:</p>
  
  <pre><code> 2011/12/14 21:57:17 [crit] 20739#0: *1 connect() to unix:///tmp/uwsgi.sock failed (13: Permission denied) while connecting to upstream, client: 10.10.3.111, server: ******, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///tmp/uwsgi.sock:", host: "****.****.**"
  </code></pre>
  
  <p>if change owner of /tmp/uwsgi.sock to nginix user in runtime (www-data), he wrote other logs</p>
  
  <pre><code>[error] 20739#0: *21 upstream prematurely closed connection while reading response header from upstream,
  </code></pre>
  
  <p>but still error 502 (</p>
  
  <p>how solving this problem? some one can help me..
  really want to use nginx+uwsgi instead of apache.
  thanks</p>
  
  <hr>
  
  <p>however, solution is near :)
  I use tcp socket now and more, change uwsgi configuration and installed a few more packages.
  was an important option --autoload.
  now uwsgi has configuration like this:</p>
  
  <pre><code>&lt;uwsgi&gt;
  &lt;module&gt;webapp&lt;/module&gt;
  &lt;socket&gt;127.0.0.1:5080&lt;/socket&gt;
  &lt;pythonpath&gt;/data/web/webapp/webapp&lt;/pythonpath&gt;
  &lt;autoload/&gt;
  &lt;daemonize&gt;/var/log/uwsgi_webapp.log&lt;/daemonize&gt;
  &lt;processes&gt;1&lt;/processes&gt;
  &lt;uid&gt;33&lt;/uid&gt;
  &lt;gid&gt;33&lt;/gid&gt;
  &lt;enable-threads/&gt;
  &lt;master/&gt;
  &lt;harakiri&gt;120&lt;/harakiri&gt;
  &lt;max-requests&gt;5000&lt;/max-requests&gt;
  &lt;/uwsgi&gt;
  </code></pre>
  
  <p>remains to solve other problem..
  uwsgi use not main system python version >_&lt;</p>
  
  <pre><code>option "pythonpath" found in plugin python26_plugin.so
  *** Starting uWSGI 0.9.8.3-debian (64bit) on [Thu Dec 15 22:52:23 2011] ***
  compiled with version: 4.6.1 on 27 July 2011 18:25:51
  uWSGI running as root, you can use --uid/--gid/--chroot options
  setgid() to 33
  setuid() to 33
  your memory page size is 4096 bytes
   *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers *** 
  uwsgi socket 0 bound to TCP address 127.0.0.1:5080 fd 4
  Python version: 2.6.7 (r267:88850, Aug  3 2011, 12:02:14)  [GCC 4.6.1]
  Python main interpreter initialized at 0xc47df0
  threads support enabled
  your server socket listen backlog is limited to 100 connections
  *** Operational MODE: single process ***
  added /data/web/webapp/webapp/ to pythonpath.
  WSGI application 0 (SCRIPT_NAME=) ready on interpreter 0xc47df0 pid: 22983 (default app)
  *** uWSGI is running in multiple interpreter mode ***
  spawned uWSGI master process (pid: 22983)
  spawned uWSGI worker 1 (pid: 22984, cores: 1)
  </code></pre>
  
  <p>he use python 2.6.7 but main system version is 2.7.2 and all python modules installed for this, so a lot of errors in the log - repeated attempts to import non-existent, one of many typical error:</p>
  
  <pre><code>  File "/usr/lib/python2.6/dist-packages/django/db/__init__.py", line 78, in &lt;module&gt;
      connection = connections[DEFAULT_DB_ALIAS]
    File "/usr/lib/python2.6/dist-packages/django/db/utils.py", line 93, in __getitem__
      backend = load_backend(db['ENGINE'])
    File "/usr/lib/python2.6/dist-packages/django/db/utils.py", line 51, in load_backend
      raise ImproperlyConfigured(error_msg)
  django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an available database backend. 
  Try using django.db.backends.XXX, where XXX is one of:
      'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
  Error was: No module named django_mongodb_engine.base
  </code></pre>
  
  <p>so.. how set version of python for uwsgi?</p>