After a very standard and minor release, our Apache/Nginx/Django/wsgi setup ceased to function with the dreaded
Premature end of script headers: django.wsgi
message in the log. There is no segfault anywhere and no other error message.
There is no expat problem (checked with sample wsgi app with and without that module include).
The server was working fine. The codebase was updated slightly and apache restarted when the horrors began.
Here is my wsgi file:
import sys
import os
sys.path.append('/home/app/')
sys.path.append('/home/app/topmodule/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'app.settings'
os.environ["CELERY_LOADER"] = "django"
import app.settings
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
The apache conf for this site is:
WSGIScriptAlias / /home/app/topmodule/django.wsgi
WSGIDaemonProcess app user=app group=app processes=6 threads=1
WSGIProcessGroup app
I also tried adding:
WSGIApplicationGroup %{GLOBAL}
but no help there.
All I’m getting is an apache Server error page and that damn premature-end error in the error log.
I did try to roll back the codebase but that didn’t do any good either which leads me to suspect its not a new code issue.
EDIT
I’ve narrowed the segfault to a line in Django’s wsgi.py.
Trace:
http://paste.pocoo.org/show/546803/
Some dumps:
http://paste.pocoo.org/show/546846/
This happens when requesting any url.
Middleware used:
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.gzip.GZipMiddleware',
I ended up reinstalling apache, mod wsgi and all related packages. At some point a warning error came up that mod_wsgi was compiled against Python 2.6.6 while the runtime is Python 2.6.4.
I rebuilt Python from source to 2.6.6 and the problem was resolved. I’m not sure if it was the minor version update or the whole rebuild that fixed it. I’m also not sure why it worked until now, and suddenly stopped working but at least its all OK now.