Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Apache2+;Python应用程序的mod_wsgi_Python_Apache_Mod Wsgi_Python 3.3 - Fatal编程技术网

使用Apache2+;Python应用程序的mod_wsgi

使用Apache2+;Python应用程序的mod_wsgi,python,apache,mod-wsgi,python-3.3,Python,Apache,Mod Wsgi,Python 3.3,我正在尝试将Apache2+mod_wsgi用于我的Python应用程序。 但是得到一个错误: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@test.local and inform them

我正在尝试将Apache2+mod_wsgi用于我的Python应用程序。 但是得到一个错误:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@test.local 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-py3

我的设置

文件夹结构:

www
└── test.local
    ├── test_site
    │   ├── manage.py
    │   └── test_site
    │       ├── __init__.py
    │       ├── settings.py
    │       ├── urls.py
    │       └── wsgi.py
    └── test_site.wsgi
/etc/主机:

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/现场可用/测试。本地

<VirtualHost 127.0.0.2:80>
    ServerAdmin webmaster@test.local
    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>
我没有忘记:

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
[Sun Mar 30 01:35:06 2014][error][client 127.0.0.1]回溯(最近一次通话):
[Sun Mar 30 01:35:06 2014][error][client 127.0.0.1]文件“/home/ube/www/test.local/test_site.wsgi”,第5行,在
[Sun Mar 30 01:35:06 2014][error][client 127.0.0.1]导入django.core.handlers.wsgi
[Sun Mar 30 01:35:06 2014][error][client 127.0.0.1]导入错误:没有名为django.core.handlers.wsgi的模块
[Sun Mar 30 01:35:06 2014][error][client 127.0.0.1]mod_wsgi(pid=15638):无法将目标wsgi脚本'/home/ube/www/test.local/test_site.wsgi'作为Python模块加载。
[Sun Mar 30 01:35:06 2014][error][client 127.0.0.1]mod_wsgi(pid=15638):处理wsgi脚本'/home/ube/www/test.local/test_site.wsgi'时发生异常。
[Sun Mar 30 01:35:06 2014][error][client 127.0.0.1]回溯(最近一次通话):
[Sun Mar 30 01:35:06 2014][error][client 127.0.0.1]文件“/home/ube/www/test.local/test_site.wsgi”,第5行,在
[Sun Mar 30 01:35:06 2014][error][client 127.0.0.1]导入django.core.handlers.wsgi
[Sun Mar 30 01:35:06 2014][error][client 127.0.0.1]导入错误:没有名为django.core.handlers.wsgi的模块
我的解决方案:

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

Django安装在哪里?Apache用户是否具有该位置的读取权限?Django安装在/usr/local/lib/python3.3/dist-packages中。测试站点位于/home/ube/www/test.local。此文件夹的权限:0775/drwxrwxr-x。
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()