2012-02-06 17 views
6

मैं अपने django प्रोजेक्ट को nginx, virtualenv, और uwsgi के साथ एक स्टेजिंग सर्वर पर सेट करने का प्रयास कर रहा हूं, लेकिन मुझे एक आयात मॉड्यूल wsgi त्रुटि मिल रही है।Django, Virtualenv, nginx + uwsgi आयात मॉड्यूल wsgi त्रुटि

यदि कोई समुदाय है तो मुझे कोई जवाब मिल सकता है ... अग्रिम धन्यवाद। मेरी Django परियोजना पर

uwsgi.py:

यह मेरा विन्यास फाइल कर रहे हैं

import os 
import sys 
import site 

site.addsitedir(os.path.join(os.environ['WORKON_HOME'],'project/lib/python2.6/site-packages')) 
sys.path.append(os.path.abspath(os.path.dirname(__file__))) 
sys.path.append(os.path.join(os.path.realpath(os.path.dirname(__file__)), '../../../')) 
sys.path.append(os.path.join(os.path.realpath(os.path.dirname(__file__)), '../../')) 

os.environ['DJANGO_SETTINGS_MODULE'] = 'project.configs.staging.settings' 

import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

Nginx विन्यास

# nginx configuration for project.maumercado.com 

server { 
    server_name project.maumercado.com; 
    access_log /home/ubuntu/logs/project/nginx/access.log; 
    error_log /home/ubuntu/logs/project/nginx/error.log; 

    location/{ 
      uwsgi_pass unix:/tmp/uwsgi.sock; 
      include /etc/nginx/uwsgi_params; 
    } 

    location /static { 
      root /home/ubuntu/django-projects/project/project/media; 
    } 
    location /media { 
      root /home/ubuntu/django-projects/project/project/media; 
    } 
} 

और, मेरे uwsgi.conf

# file: /etc/init/uwsgi.conf 
description "uWSGI starter" 

start on (local-filesystems and runlevel [2345]) 
stop on runlevel [016] 

respawn 

# home - is the path to our virtualenv directory 
# pythonpath - the path to our django application 
# module - the wsgi handler python script 

exec /home/ubuntu/ve/project/bin/uwsgi \ 
--uid www-data \ 
--pythonpath /home/ubuntu/django-projects/project/project/configs/staging/ \ 
--socket /tmp/uwsgi.sock \ 
--chmod-socket \ 
--module wsgi \ 
--logdate \ 
--optimize 2 \ 
--processes 2 \ 
--master \ 
--logto /home/ubuntu/logs/project/uwsgi.log 

Nginx लो gs access.log में 500 के अलावा कुछ भी राज्य नहीं है, इतने heres uwsgi.log:

Mon Feb 6 13:58:23 2012 - *** Starting uWSGI 1.0.2.1 (32bit) on [Mon Feb 6 13:58:23 2012] *** 
Mon Feb 6 13:58:23 2012 - compiled with version: 4.4.5 on 06 February 2012 12:32:36 
Mon Feb 6 13:58:23 2012 - current working directory:/
Mon Feb 6 13:58:23 2012 - detected binary path: /home/ubuntu/ve/project/bin/uwsgi 
Mon Feb 6 13:58:23 2012 - setuid() to 1000 
Mon Feb 6 13:58:23 2012 - your memory page size is 4096 bytes 
Mon Feb 6 13:58:23 2012 - chmod() socket to 666 for lazy and brave users 
Mon Feb 6 13:58:23 2012 - uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3 
Mon Feb 6 13:58:23 2012 - Python version: 2.6.6 (r266:84292, Sep 15 2010, 16:02:57) [GCC 4.4.5] 
Mon Feb 6 13:58:23 2012 - Set PythonHome to /home/ubuntu/ve/project 
Mon Feb 6 13:58:23 2012 - Python main interpreter initialized at 0x9a9d740 
Mon Feb 6 13:58:23 2012 - your server socket listen backlog is limited to 100 connections 
Mon Feb 6 13:58:23 2012 - *** Operational MODE: preforking *** 
Mon Feb 6 13:58:23 2012 - added /home/ubuntu/django-projects/project/ to pythonpath. 
ImportError: No module named wsgi 
Mon Feb 6 13:58:23 2012 - unable to load app 0 (mountpoint='') (callable not found or import error) 
Mon Feb 6 13:58:23 2012 - *** no app loaded. going in full dynamic mode *** 
Mon Feb 6 13:58:23 2012 - *** uWSGI is running in multiple interpreter mode *** 
Mon Feb 6 13:58:23 2012 - spawned uWSGI master process (pid: 551) 
Mon Feb 6 13:58:23 2012 - spawned uWSGI worker 1 (pid: 588, cores: 1) 
Mon Feb 6 13:58:23 2012 - spawned uWSGI worker 2 (pid: 589, cores: 1) 

तरह से मैं अपने प्रोजेक्ट की स्थापना की यह से कोई लेना देना नहीं है, तो मुझे पता नहीं है, लेकिन वैसे भी यहाँ है

manage.sh

#!/bin/bash 

python ./project/configs/${DEPLOYMENT_TARGET:="common"}/manage.py $* 

और सिर्फ मामले में यह कैसे मैं एक Django परियोजना की स्थापना की है है:

project 
|-manage.sh -> this fellow is redirected to settings.py (production, common or staging) 
|-requirements.txt 
|-README 
|-dashbard.py 
|-project.sqlite 
|- project/ 
    |- apps 
     |- accounts 
     |-other internal apps 
    |- configs 
     |- common -> for local development 
      |-settings.py 
      |-manage.py 
      |-urls 
     |-staging 
      |-manage.py 
      |-settings.py 
      |-wsgi.py 
      |-logging.conf 
     |-production 
      |-manage.py 
      |-settings.py 
      |-wsgi.py 
      |-logging.conf 
    |-media 
    |-templates 
फ़ाइल है कि मैं Django उपयोगिताओं रीडायरेक्ट करने के लिए उपयोग करने का प्रबंधन

import os 
import sys 
import site 

site.addsitedir(os.path.join('/home/ubuntu/ve','project/lib/python2.6/site-packages')) 
sys.path.append(os.path.abspath(os.path.dirname(__file__))) 
sys.path.append(os.path.join(os.path.realpath(os.path.dirname(__file__)), '../../../')) 
sys.path.append(os.path.join(os.path.realpath(os.path.dirname(__file__)), '../../')) 

os.environ['DJANGO_SETTINGS_MODULE'] = 'project.configs.staging.settings' 

import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

: 0

उत्तर

5

मैं wsgi.py अद्यतन इस तरह देखने के लिए (आप PYTHONPATH निर्देशों की एक असीमित श्रृंखला निर्दिष्ट कर सकते हैं) मेरे uwsgi.conf फ़ाइल अब इस तरह दिखता है:

# file: /etc/init/uwsgi.conf 
description "uWSGI starter" 

start on (local-filesystems and runlevel [2345]) 
stop on runlevel [016] 

respawn 

# home - is the path to our virtualenv directory 
# pythonpath - the path to our django application 
# module - the wsgi handler python script 

exec /home/ubuntu/ve/project/bin/uwsgi \ 
--uid ubuntu \ 
--pythonpath /home/ubuntu/django-projects/project/project/configs/staging \ 
-H /home/ubuntu/ve/project \ 
--socket /tmp/uwsgi.sock \ 
--chmod-socket 644 \ 
--module wsgi \ 
--logdate \ 
--optimize 2 \ 
--processes 2 \ 
--master \ 
--logto /home/ubuntu/logs/project/uwsgi.log 

और मेरे nginx साइट-उपलब्ध फ़ाइल इस तरह दिखता है:

# file: /etc/nginx/sites-available/yourdomain.com 
# nginx configuration for project.maumercado.com 

server { 
     listen 80; 
     charset utf-8; 
     server_name project.maumercado.com; 
     access_log /home/ubuntu/logs/project/nginx/access.log; 
     error_log /home/ubuntu/logs/project/nginx/error.log; 

     location ^~ /cache/ { 
       root /home/ubuntu/django-projects/project/project/media; 
       expires max; 
     } 

     location/{ 
       uwsgi_pass unix:/tmp/uwsgi.sock; 
       include /etc/nginx/uwsgi_params; 
     } 
} 

और अब यह सही काम कर रहा है, मुझे शैलियों के साथ कुछ समस्याएं थीं क्योंकि सीएसएस फाइलों में अजीब पात्रों का उपयोग किया जा रहा था।

अब मैं जानना चाहता हूं कि मुझे क्या करना चाहिए जब मुझे यूवीजीआई के साथ एक ही सर्वर में और अधिक परियोजनाएं चलाने की ज़रूरत है?

+1

मैं कई परियोजनाओं के लिए क्या करता हूं यूवस्गी डेबियन पैकेज का उपयोग करता है। यह init स्क्रिप्ट के साथ आता है, कुछ डिफ़ॉल्ट .ini सेटिंग्स फ़ाइलें, और प्रत्येक परियोजना का प्रबंधन करता है। आपको केवल प्रत्येक फ़ाइल के लिए कॉन्फ़िगरेशन की आवश्यकता होती है और प्रत्येक के लिए एक अलग सॉकेट (डिफ़ॉल्ट रूप से संभाला जाता है) और वे सभी एक ही सिस्टम पर अच्छी तरह से चलेंगे।भले ही आप डेबियन पर न हों, फिर भी आप डेबियन पैकेज से इनिट स्क्रिप्ट और कॉन्फ़िगरेशन लेआउट का उपयोग कर सकते हैं: http://ftp.de.debian.org/debian/pool/main/u/uwsgi/uwsgi_1.2.3 + dfsg.orig.tar.gz – freb

1

निर्देशिका PYTHONPATH को wsgi.py फ़ाइल युक्त जोड़ना सुनिश्चित करें

+0

--pythonpath/home/ubuntu/django-projects/project/project/configs/staging/<- पहले से चेक किया गया है, जहां मैं wsgi.py फ़ाइल रखता हूं। या आप कुछ और मतलब है? धन्यवाद! – maumercado

+0

/home/ubuntu/django-projects/project/project_apps/config/staging/home/ubuntu/django-projects/project/project/configs/staging के बजाय स्टेजिंग/स्टेजिंग नहीं होना चाहिए? – roberto

+0

ओह मुझे मिल गया ... हाँ वास्तव में यह वही तरीका है, मैंने सेट अप किया है "project_apps" फ़ोल्डर वास्तव में प्रोजेक्ट कहलाता है, बीमार इसे संपादित करें! – maumercado

संबंधित मुद्दे