2012-02-06 13 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 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をしません。私は、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 

manage.sh

#!/bin/bash 

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

と念のために、これは私がDjangoのプロジェクトを設定している方法です0

答えて

5

(あなたはPYTHONPATHディレクティブの無制限のシリーズを指定することができます)PYTHONPATHにwsgi.pyファイルを含むディレクトリを追加してください:

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() 

をマイ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 Debianパッケージを使用することです。 initスクリプト、いくつかのデフォルトの.ini設定ファイルが付属しており、それぞれのプロジェクトを管理しています。各ファイルには設定が必要で、それぞれに異なるソケットが必要です(デフォルトで処理されます)。これらは同じシステム上でうまく動作します。Debian上にいなくても、Debianパッケージのinitスクリプトと設定のレイアウトは引き続き使用できます:http://ftp.de.debian.org/debian/pool/main/u/uwsgi/uwsgi_1.2.3 + dfsg.orig.tar.gz – freb

1

私はこのように見て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

関連する問題