2014-03-29 28 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 =)。

相关问题