apache2 + django + mod_wsgi没有响应

时间:2013-11-06 09:38:36

标签: django apache mod-wsgi

我正在尝试使用apache2 + mod_wsgi模块部署我的工作django应用程序。这是我的apache配置:

anton@ru:~$ cat /etc/apache2/sites-available/default
Alias /static/ /home/anton/mysite/static/

<Directory /home/anton/mysite/static>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /home/anton/mysite/mysite/wsgi.py

<Directory /home/anton/mysite>
Order allow,deny
Allow from all
</Directory>

和WCGI配置:

anton@ru:~$ cat /home/anton/mysite/mysite/wsgi.py
import os
import sys
sys.path.append('/home/anton/mysite')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

使用调试输出(print'bla-bla')我发现wsgi.py有效。但是后来http请求没有得到apache的任何响应。你能帮我理解为什么吗?谢谢!

更新 我已经像这样开启了日志:

ErrorLog /home/anton/error.log
CustomLog /home/anton/custom.log combined

以下是重新加载服务时错误日志中发生的情况:

[Wed Nov 06 05:43:14 2013] [notice] Graceful restart requested, doing restart
[Wed Nov 06 05:43:14 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
[Wed Nov 06 05:43:14 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Wed Nov 06 05:43:14 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Wed Nov 06 05:43:14 2013] [notice] Apache/2.2.22 (Debian) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations

在请求“mysite.com/”时,error.log和custom.log中没有任何反应。静态数据有效:

85.141.191.57 - - [06/Nov/2013:05:44:37 -0500] "GET /static/main.css HTTP/1.1" 304 213 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36"
85.141.191.57 - - [06/Nov/2013:05:44:38 -0500] "GET /static/main.css HTTP/1.1" 304 212 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36"

解: 这里的问题是python版本与编译的python mod_wsgi的版本不匹配。我从源代码构建了mod_wsgi,这解决了我的问题。

1 个答案:

答案 0 :(得分:1)

尝试添加:

WSGIApplicationGroup %{GLOBAL}

为什么阅读:

通常,还建议使用mod_wsgi守护程序模式。

虽然这不应该是问题。