2014-05-16 2 views
1

아파치와 함께 django를 사용하고 싶습니다. 내 디렉토리 트리/홈/avlahop에서아파치는 django 프로젝트에서 설정을 가져올 수 없습니다.

WSGIPythonPath /home/avlahop/development/django/rhombus2 
<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName myrhombus.com 
    ServerAlias www.myrhombus.com 
    DocumentRoot /home/avlahop/development/django/rhombus2 
    WSGIScriptAlias//home/avlahop/development/django/rhombus2/rhombus/wsgi.py 
    <Directory /home/avlahop/development/django/rhombus2/rhombus> 
     <Files wsgi.py> 
      Require all granted 
     </Files> 
     Options Indexes FollowSymLinks 
     AllowOverride None 
     Require all granted 
    </Directory> 
</VirtualHost> 

모든

import os, sys 

root = os.path.join(os.path.dirname(__file__),'..') 
sys.path.insert(0, root) 
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rhombus.settings") 



# This application object is used by any WSGI server configured to use this 
# file. This includes Django's development server, if the WSGI_APPLICATION 
# setting points here. 
from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application() 

# Apply WSGI middleware here. 
# from helloworld.wsgi import HelloWorldApplication 
# application = HelloWorldApplication(application) 

내 site.conf 파일은 다음 코드가 다음

/home/avlahop/development/django/rhombus2 
├── accounts 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   ├── models.py 
│   ├── tests.py 
│   ├── urls.py 
│   ├── urls.pyc 
│   ├── views.py 
│   └── views.pyc 
├── admin 
│   ├── css 
│   ├── img 
│   │   ├── gis 
│   └── js 
├── customer 
│   ├── migrations 
│   ├── models.py 
│   ├── models.pyc 
│   ├── views.py 
│   └── views.pyc 
├── __init__.py 
├── __init__.pyc 
├── manage.py 
├── media 
├── mycal 
├── mypil 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   ├── models.py 
│   ├── tests.py 
│   ├── urls.py 
│   ├── urls.pyc 
│   ├── views.py 
│   └── views.pyc 
├── rhombus 
│   ├── api.py 
│   ├── api.pyc 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   ├── rhombus.db 
│   ├── settings.py 
│   ├── settings.pyc 
│   ├── urls.py 
│   ├── urls.pyc 
│   ├── wsgi.py 
│   └── wsgi.pyc 
├── scripts 
│   ├── create_data_files.py 
│   ├── create_data_files.pyc 
│   ├── find_server.py 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   └── populatedb.py 
├── settings 
├── static 
├── tastypie 
├── templates 

wsgi.py (그리고 가능)/개발/django/rhombus2 (루트 포함)는 다른 사람에게 rx 인 755로 chmode됩니다. 하지만 다음 오류가 발생합니다.

ImportError: Could not import settings 'rhombus.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named rhombus.settings 

무엇이 잘못 되었습니까? 다른 사이트 (다른 ​​conf 파일에있는 또 다른 가상 호스트)에서 동일한 작업을 수행하고 권한이 거부되었습니다. 그리고 위 코드를 붙여 복사 한 다음 경로를 변경했습니다. 따라서 2 개의 사이트가 동일한 코드로 서로 다른 오류가 발생합니다. 나는 정말로 여기에서 좌절하고있다. 나는 PHP에 가고 싶지 않아 .... PHP를 배포하기 쉽습니다 ...

답변

0

Django documentation에 명시된 바와 같이 당신이 파이썬 경로를 지정해야합니다 다음과 같이 대안으로

WSGIScriptAlias//path/to/mysite.com/mysite/wsgi.py 
WSGIPythonPath /path/to/mysite.com 

, 당신 귀하의 경우에는

WSGIDaemonProcess [other args] python-path=/path/to/mysite.com 

python_path argumentWSGIDaemonProcess 지시어를 사용 할 수 있습니다 (이뿐만 아니라 Django docs에 명시되어있다) /path/to/mysite.com는해야 /home/avlahop/development/django/rhombus2

,536,

또한, (1) 사이트를 실행하지 않아도되고 (2) 특정 상황에서 공격자가 소스 코드에 액세스 할 수 있으므로 DocumentRoot 아래에 소스 코드를 삽입하는 것은 나쁜 습관으로 간주됩니다. 내가 실수하지 않는다면 정적 파일 만 DocumentRoot 아래에 있어야합니다.

+0

하지만 알겠습니다. 내 site.conf의 첫 번째 줄을보십시오. DocumentRoot 안에 무엇을 넣어야합니까? 템플릿과 정적 만? 설정 파일의 템플릿 폴더를 변경해야합니까? 나는 그렇게 생각한다. 이것은 매우 유연하지 않습니다. WSGIPythonPath가 다른 많은 가상 호스트가 있다면 어떻게 될까요? 나는 그들을 하나의 conf에 넣을 수 없다. 옳은? – Apostolos

+0

'WSGIPythonPath '를 파일 시스템 트리 위아래로 움직여보십시오. Templates는 DocumentRoot 밖에 있어야합니다. 템플릿 폴더는 실수가 아니라면 상대 경로 여야합니다. 절대 경로를 지정하지 않으면 변경하지 않아도됩니다. 가상 호스트가 많은 경우 각 가상 호스트에 대해 mod_wsgi를 구성해야합니다. – J0HN

+0

또한 오류로 인해 설정 파일을 가져올 수없는 경우 동일한 오류가 나타납니다. 해당 virtualenv로 전환하고, 대화 형 Python 콘솔을 실행하고 설정 파일을 가져 오십시오. 오류가있을 수 있습니다. – J0HN

관련 문제