Apache2无法加载wsgi.py

时间:2015-04-25 09:35:44

标签: django apache wsgi

我正在使用Ubuntu 14.10 X86_64系统,其软件如下:

  • python 3.4
  • 的apache2
  • 中的libapache2-MOD-WSGI-PY3
  • django1.8

我在这条路上用django1.8创建了一个项目:

if (Session["LogedUserID"] != null)
{
   int p = Convert.ToInt32(Session["LogedUserID"]);
   var patients = db.patients.Where(a => a.nurse_patient.Select(x => x.n_id).Equals(p)).ToList();
   return View(patients);
}

我注意到django-admin startproject默认会生成一个wsgi.py文件,但我没有改变它的内容。

我在官方文档(如何使用Django with Apache和mod_wsgi)下配置了apache2:

我修改了000-default.conf,因为我不想设置另一个虚拟主机。这就是我添加的内容:

/var/www/html/koorimeo

之后我在apache2.conf中声明了WSGIAlias和WSGIPythonPath:

#000-default.conf
<VirtualHost *:80>
...
<Directory /var/www/html/koorimeo/koorimeo>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
...
</VirtualHost>

完成文件设置后,我重新启动了apache2服务并登录到127.0.0.1/koorimeo,它返回了500错误消息... 我查找了错误日志文件并收到以下错误消息:

#apache2.conf
#I want to leave "/" for other use...
WSGIScriptAlias /koorimeo /var/www/html/koorimeo/koorimeo/wsgi.py
WSGIPythonPath /var/www/html/koorimeo/koorimeo

根据这些消息我发现apache2找不到这个模块:

bing@k-lab:/var/log/apache2$ tail error.log
[Sat Apr 25 14:35:31.214661 2015] [:notice] [pid 16997:tid 140004070725504] mod_python: Creating 8 session mutexes based on 6 max processes and 25 max threads.
[Sat Apr 25 14:35:31.214705 2015] [:notice] [pid 16997:tid 140004070725504] mod_python: using mutex_directory /tmp 
[Sat Apr 25 14:35:31.232634 2015] [:warn] [pid 16997:tid 140004070725504] mod_wsgi: Compiled for Python/3.4.0.
[Sat Apr 25 14:35:31.232682 2015] [:warn] [pid 16997:tid 140004070725504] mod_wsgi: Runtime using Python/2.7.6.
[Sat Apr 25 14:35:31.232766 2015] [mpm_event:notice] [pid 16997:tid 140004070725504] AH00489: Apache/2.4.7 (Ubuntu) mod_python/3.3.1 Python/2.7.6 mod_wsgi/3.4 configured -- resuming normal operations
[Sat Apr 25 14:35:31.232786 2015] [core:notice] [pid 16997:tid 140004070725504] AH00094: Command line: '/usr/sbin/apache2'
[Sat Apr 25 14:35:32.234958 2015] [core:notice] [pid 16997:tid 140004070725504] AH00051: child pid 18325 exit signal Aborted (6), possible coredump in /etc/apache2
[Sat Apr 25 14:35:32.235070 2015] [core:notice] [pid 16997:tid 140004070725504] AH00051: child pid 18326 exit signal Aborted (6), possible coredump in /etc/apache2
[Sat Apr 25 14:35:34.041184 2015] [:error] [pid 18599:tid 140003960342272] [client 127.0.0.1:51134] mod_wsgi (pid=18599): Target WSGI script '/var/www/html/koorimeo/koorimeo/wsgi.py' cannot be loaded as Python module., referer: http://localhost/
[Sat Apr 25 14:35:34.041279 2015] [:error] [pid 18599:tid 140003960342272] [client 127.0.0.1:51134] mod_wsgi (pid=18599): Exception occurred processing WSGI script '/var/www/html/koorimeo/koorimeo/wsgi.py'., referer: http://localhost/

所以我复制了这条路径并尝试让我清楚这个文件确实存在:

/var/www/html/koorimeo/wsgi.py

并且系统返回此消息,告诉我该文件确实存在...

bing@k-lab:/var/log/apache2$ ls /var/www/html/koorimeo/koorimeo/wsgi.py -l

我还确保我已经安装了libapache2-mod-wsgi-py3,我确实在正确的位置找到了wsgi.so。

我在mode-enable中找到wsgi.load并将wsgi.so指向正确的位置:

-rw-rw-r-- 1 bing bing 389  4月 25 14:21 /var/www/html/koorimeo/koorimeo/wsgi.py

所以......我很困惑......

请告诉我为什么apache2找不到 wsgi.py 文件?

1 个答案:

答案 0 :(得分:2)

如果你没有使用它,请从Apache中删除mod_python。

你的mod_wsgi模块是为Python 3.4.0编译的,但mod_python是为2.7.6编译的。因为mod_python使用的是不同的版本,所以它会覆盖使用的Python版本,这将阻止mod_wsgi工作。

阅读文档中的许多部分: