How to run Django 1.3/1.4 on uWSGI on nginx on EC2 (Apache2 works)

Posted by Tadeck on Server Fault See other posts from Server Fault or by Tadeck
Published on 2012-04-03T15:22:17Z Indexed on 2012/07/03 3:18 UTC
Read the original article Hit count: 500

Filed under:
|
|
|
|

I am posting a question on behalf of my administrator. Basically he wants to set up Django app (made on Django 1.3, but will be moving to Django 1.4, so it should not really matter which one of these two will work, I hope) on WSGI on nginx, installed on Amazon EC2.

The app runs correctly when Django's development server is used (with ./manage.py runserver 0.0.0.0:8080 for example), also Apache works correctly. The only problem is with nginx and it looks there is something else wrong with nginx / WSGI or Django configuration.

His description is as follows:

Server has been configured according to many tutorials, but unfortunately Nginx and uWSGI still do not work with application.

ProjectName.py:

import os, sys, wsgi

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ProjectName.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

I run uWSGI by comand:

uwsgi -x /etc/uwsgi/apps-enabled/projectname.xml

XML file:

<uwsgi>
        <chdir>/home/projectname</chdir>
        <pythonpath>/usr/local/lib/python2.7</pythonpath>
        <socket>127.0.0.1:8001</socket>
        <daemonize>/var/log/uwsgi/proJectname.log</daemonize>
        <processes>1</processes>
        <uid>33</uid>
        <gid>33</gid>
        <enable-threads/>
        <master/>
        <vacuum/>
        <harakiri>120</harakiri>
        <max-requests>5000</max-requests>
        <vhost/>
</uwsgi>

In logs from uWSGI:

*** no app loaded. going in full dynamic mode ***

In logs from Nginx:

XXX.com [pid: XXX|app: -1|req: -1/1] XXX.XXX.XXX.XXX () {48 vars in 989 bytes} [Date] GET / => generated 46 bytes in 77 m
secs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0)
added /usr/lib/python2.7/ to pythonpath.
Traceback (most recent call last):
  File "./ProjectName.py", line 26, in <module>
    from django.core.wsgi import get_wsgi_application
ImportError: No module named wsgi
unable to load app SCRIPT_NAME=XXX.com|

Example tutorials that were used:

Do you have any idea what has been done incorrectly, or what should be done to make Django work on uWSGI on nginx on EC2?

© Server Fault or respective owner

Related posts about nginx

Related posts about amazon-ec2