2012-02-06 2 views
6

Im은 dginogo 프로젝트를 nginx, virtualenv 및 uwsgi를 사용하여 준비 서버에 설치하려고 시도하지만 가져 오기 모듈 wsgi 오류가 계속 발생합니다.Django, Virtualenv, nginx + uwsgi 가져 오기 모듈 wsgi 오류

답변을 찾을 수있는 커뮤니티가있는 경우 ... 미리 감사드립니다. 내 장고 프로젝트에

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 lo 어쨌든을 heres

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) 

내 프로젝트를 설정하는 방식이 그것과 아무 상관이 있는지 잘 모르겠지만, : GS는 access.log의에서 500 이외의 아무것도 상태, 그래서를 heres uwsgi.log을하지 않습니다

manage.sh

#!/bin/bash 

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

그냥 경우에 이것이 내가 장고 프로젝트를 설정 한 방법은 다음과 같습니다 :

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 
을 내가 장고 유틸리티를 리디렉션하는 데 사용하는 파일 관리

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

(당신은 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; 
     } 
} 

완벽하게 작동하기 때문에 CSS 파일에서 ñ처럼 사용되는 이상한 문자 때문에 스타일에 몇 가지 문제가있었습니다.

이제 uwsgi를 사용하여 동일한 서버에서 더 많은 프로젝트를 실행해야 할 때 어떻게해야합니까?

+1

여러 프로젝트에서 내가하는 일은 uwsgi 데비안 패키지를 사용하는 것입니다. init 스크립트, 일부 기본 .ini 설정 파일과 함께 제공되며 각 프로젝트를 관리합니다. 각 파일에 대한 구성과 각 파일에 대한 다른 소켓이 필요하며 (기본적으로 처리됨) 모두 동일한 시스템에서 잘 실행됩니다.데비안에 있지 않더라도 데비안 패키지의 init 스크립트와 설정 레이아웃을 사용할 수 있습니다 : http://ftp.de.debian.org/debian/pool/main/u/uwsgi/uwsgi_1.2.3 + dfsg.orig.tar.gz – freb

1

하면 PYTHONPATH에 wsgi.py 파일이 들어있는 디렉토리를 추가해야합니다 내가 같이하는 wsgi.py 업데이트

+0

- pythonpath/home/ubuntu/django-projects/project/project/configs/staging/<- 이미 확인 했으므로 wsgi.py 파일을 보관합니다. 아니면 뭔가 다른 것을 의미합니까? 감사! – maumercado

+0

은/home/ubuntu/django-projects/project/project/configs/staging 대신/home/ubuntu/django-projects/project/project_apps/configs/staging이 아니어야합니까? – roberto

+0

오, 알았어 ... 그래, 실제로 그 방법은, 내가 거기에 넣어 "project_apps"폴더 실제로 프로젝트, 아픈 편집이라고! – maumercado