2014-03-29 39 views
0

我正在嘗試爲我的Python應用程序使用Apache 2 + mod_wsgi。 但得到一個錯誤:使用Apache 2 + mod_wsgi for Python應用程序

Internal Server Error 
The server encountered an internal error or misconfiguration and was unable to complete your request. 
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error. 
More information about this error may be available in the server error log. 

我的配置:Ubuntu的12.04,Apache2的,Python3.3,Django的1.6,中的libapache2-MOD-WSGI-PY 3。

我的設置。

文件夾結構:

www 
└── test.local 
    ├── test_site 
    │ ├── manage.py 
    │ └── test_site 
    │  ├── __init__.py 
    │  ├── settings.py 
    │  ├── urls.py 
    │  └── wsgi.py 
    └── test_site.wsgi 

/etc/hosts文件:

127.0.0.1 localhost 
127.0.0.2 test.local 
127.0.1.1 ube-home 

# The following lines are desirable for IPv6 capable hosts 
::1  ip6-localhost ip6-loopback 
fe00::0 ip6-localnet 
ff00::0 ip6-mcastprefix 
ff02::1 ip6-allnodes 
ff02::2 ip6-allrouters 

/etc/apache2/sites-available/test.local

<VirtualHost 127.0.0.2:80> 
    ServerAdmin [email protected] 
    ServerName test.local 
     ServerAlias www.test.local 

    WSGIScriptAlias//home/ube/www/test.local/test_site.wsgi 

    DocumentRoot /home/ube/www/test.local 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride All 
    </Directory> 
    <Directory /home/ube/www/test.local/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride All 
     Order allow,deny 
     allow from all 
    </Directory> 

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
    <Directory "/usr/lib/cgi-bin"> 
     AllowOverride All 
     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
     Order allow,deny 
     Allow from all 
    </Directory> 

    ErrorLog ${APACHE_LOG_DIR}/error.log 

    # Possible values include: debug, info, notice, warn, error, crit, 
    # alert, emerg. 
    LogLevel warn 

    CustomLog ${APACHE_LOG_DIR}/access.log combined 

    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride ALl 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 
</VirtualHost> 

/家庭/ UBE/www/test.local/test_site.wsgi

import os 
import sys 
sys.path.append('/home/ube/www/test.local/') 
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_site.settings' 
import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

我沒有忘記:

sudo a2ensite test.local 
sudo service apache2 restart 

錯誤日誌說:

[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] Traceback (most recent call last): 
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] File "/home/ube/www/test.local/test_site.wsgi", line 5, in <module> 
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1]  import django.core.handlers.wsgi 
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] ImportError: No module named django.core.handlers.wsgi 
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] mod_wsgi (pid=15638): Target WSGI script '/home/ube/www/test.local/test_site.wsgi' cannot be loaded as Python module. 
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] mod_wsgi (pid=15638): Exception occurred processing WSGI script '/home/ube/www/test.local/test_site.wsgi'. 
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] Traceback (most recent call last): 
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] File "/home/ube/www/test.local/test_site.wsgi", line 5, in <module> 
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1]  import django.core.handlers.wsgi 
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] ImportError: No module named django.core.handlers.wsgi 
+0

錯誤日誌說? –

+0

Django在哪裏安裝? Apache用戶是否具有對該位置的讀權限? –

+0

Django安裝在/usr/local/lib/python3.3/dist-packages中。測試網站位於/home/ube/www/test.local。此文件夾的權利:0775/drwxrwxr-x。 –

回答

1

解決方案在我的情況:

import os 
import sys 
sys.path.append('/home/ube/www/test.local/test_site/') 
sys.path.append('/home/ube/www/test.local/') 
sys.path.append('/home/ube/www/') 
sys.path.append('/usr/local/lib/python3.3/dist-packages') 

os.environ['DJANGO_SETTINGS_MODULE'] = 'test_site.settings' 

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

我增加了更多的sys.path =)。

相關問題