headers 之前的 Django 脚本输出结束

Django End of script output before headers

我的其中一台服务器会定期停止提供内容,并且在 Vhost 错误日志中发现以下错误:

[Mon Feb 02 10:27:41.692362 2015] [core:error] [pid 13013] [client xxx.xxx.xxx.xxx:41537] End of script output before headers: wsgi.py
[Mon Feb 02 10:27:41.692365 2015] [core:error] [pid 13025] [client xxx.xxx.xxx.xxx:41188] End of script output before headers: wsgi.py
[Mon Feb 02 10:27:41.692423 2015] [core:error] [pid 14787] [client xxx.xxx.xxx.xxx:36388] End of script output before headers: wsgi.py
[Mon Feb 02 10:27:41.692451 2015] [core:error] [pid 12994] [client xxx.xxx.xxx.xxx:38770] End of script output before headers: wsgi.py

在此之后,apache 锁定并停止提供内容。帮助最感激。

wsgi.py:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

虚拟主机:

WSGIScriptAlias / /var/www/vhosts/zipper/src/core/wsgi.py
WSGIDaemonProcess zipper python-path=/var/www/vhosts/zipper/src:/var/www/vhosts/.virtualenvs/zipper/lib/python2.7/site-packages
WSGIProcessGroup zipper

<Directory /var/www/vhosts/zipper/src/>
    <Files wsgi.py>
         Require all granted
    </Files>
</Directory>

编辑 #1

Django 版本:1.6.4 Mod_WSGI版本:3.4-4ubuntu2.1.14.04.2

ServerName localhost
ServerAlias localhost
ServerAdmin raghav@xyz.com

<Directory /var/www/mysite/mysite>
AddHandler wsgi-script .py
Options +ExecCGI
</Directory>

DocumentRoot /var/www/mysite
WSGIDaemonProcess myproject python-path=/var/www/mysite:/var/www/environ/lib/python2.7/site-packages
#WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py

WSGIApplicationGroup %{GLOBAL}

<Directory /var/www/mysite/mysite/>
order deny,allow
Allow from all
</Directory>

看了几个博客后我也遇到了同样的问题,这个配置对我有用。 试试这个

尝试添加指令:

WSGIApplicationGroup %{GLOBAL}

在 WSGIProcessGroup 行之后。

各种带有 C 扩展组件的第三方 Python 软件包存在已知问题,这意味着它们无法与 Python 子解释器一起正常工作。该指令强制应用程序在主解释器上下文中 运行。这样的模块就很开心了。