2014-05-23 2 views
1

Django 앱을 운이없는 Apache 서버에 배포하려고합니다. 나는 WSGI 샘플 애플리케이션을 성공시키고 빈 Django 프로젝트를 호스트하려고 시도했다.아파치와 wsgi가있는 Django가 ImportError를 던졌습니다.

""" 
WSGI config for myapp project. 

It exposes the WSGI callable as a module-level variable named ``application``. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ 
""" 

import os 
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings") 

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

난에 wsgi.conf 있습니다

[notice] Apache/2.2.22 (Debian) PHP/5.4.4-14+deb7u9 mod_python/3.3.1 Python/2.7.3 mod_wsgi/2.7 configured -- resuming normal operations 
[error] [client x.x.x.x] mod_wsgi (pid=8300): Exception occurred processing WSGI script '/usr/local/www/django/myapp/wsgi.py'. 
[error] [client x.x.x.x] Traceback (most recent call last): 
[error] [client x.x.x.x] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 187, in __call__ 
[error] [client x.x.x.x]  self.load_middleware() 
[error] [client x.x.x.x] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 44, in load_middleware 
[error] [client x.x.x.x]  for middleware_path in settings.MIDDLEWARE_CLASSES: 
[error] [client x.x.x.x] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 54, in __getattr__ 
[error] [client x.x.x.x]  self._setup(name) 
[error] [client x.x.x.x] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 49, in _setup 
[error] [client x.x.x.x]  self._wrapped = Settings(settings_module) 
[error] [client x.x.x.x] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 132, in __init__ 
[error] [client x.x.x.x]  % (self.SETTINGS_MODULE, e) 
[error] [client x.x.x.x] ImportError: Could not import settings 'myapp.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named myapp.settings 

내 wsgi.py은 다음과 같다 :가 manage.py의 runserver 제대로 작동하지만 아파치를 사용하는 경우, 다음과 같은 오류가 발생합니다 아파치에 대한 conf.d 라이브러리 :

<VirtualHost *:80> 
ServerName myapp.example.com 
ServerAlias myapp 
ServerAdmin [email protected] 
DocumentRoot /var/www 

<Directory /usr/local/www/django> 
    Order allow,deny 
    Allow from all 
</Directory> 

WSGIDaemonProcess myapp processes=2 threads=15 display-name=%{GROUP} 
WSGIProcessGroup myapp 

WSGIScriptAlias /myapp /usr/local/www/django/myapp/wsgi.py 
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so 

</VirtualHost> 

WSGIPythonPath /usr/local/www/django/myapp 

[SOLVED] 감사합니다, 나는 모든 것을 다시 시작 내 구성 파일에 제안 된 수정을했고, 지금은 일하고있어. 두 가지 제안을 모두 올바르게 표시 할 수는 없었지만 두 가지 모두 필요하다고 생각하고 다시 설치 한 후 사라지는 세 번째 (네 번째, 다섯 번째 ...) 버그가있었습니다.

+0

앱 레이아웃은 무엇입니까? 정확히 설정 파일은 어디에 있습니까? –

+0

앱 레이아웃은 django가 생성 한 레이아웃입니다. –

+0

그렇다면 settings.py에 대한 전체 파일 경로 *는 무엇입니까? –

답변

2

apache2/wsgi 설정에 대한 이전 가이드를 사용해온 것처럼 보입니다. https://code.google.com/p/modwsgi/wiki/InstallationInstructions

어쨌든 특정 문제는 wsgi 응용 프로그램이 python 경로를 올바르게 선택하지 않는다는 것입니다. 설정 파일이 /usr/local/www/django/myapp/settings.py에있다이

<VirtualHost *:80> 
    ServerName myapp.example.com 
    ServerAlias myapp 
    ServerAdmin [email protected] 

    DocumentRoot /usr/local/www/django/myapp 
    WSGIDaemonProcess myapp processes=2 threads=15 display-name=%{GROUP} python-path=/usr/local/www/django/myapp:/path/to/system/python/site-packages 
    WSGIProcessGroup myapp 
    WSGIScriptAlias//usr/local/www/django/myapp/wsgi.py 

    <Directory /usr/local/www/django/myapp> 
     <Files wsgi.py> 
      Order allow,deny 
      Allow from all 
     </Files> 
    </Directory> 
</VirtualHost> 
+0

다시 시작하기로 결정 했으므로 제안 된 수정 사항을 추가하고 작동 방식을 확인합니다. –

+0

여전히 같은 오류가 발생합니다. –

+0

Graeme Dumpleton이 질문에 대한 자신의 의견을 남겼습니다. 그는 mod_wsgi의 개발자이기 때문에 누구보다 잘 알게 될 것입니다. – hellsgate

1

같은 것을 당신에게 가상 호스트의 conf의 변경,하지만 당신은 PYTHONPATH를 설정 한에/usr/지방/www /에서 django/myapp로 설정하고 DJANGO_SETTINGS_MODULE을 "myapp.settings"로 설정합니다. 설정이 myapp/myapp/settings에있는 경우에만 적합합니다. "myapp"에 대한 참조 중 하나를 삭제하십시오.

+0

시도했지만 운이 없다 :( –