Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django, apache, mod_wsgi - Error: Premature end of script headers

Apache logs in mode debug:

[Tue Dec 21 11:36:33 2010] [info] [client 1.53.149.114] mod_wsgi (pid=24831, process='mysite', application='mysite.com|'): Loading WSGI script '/home/anhtran/webapps/mysite.com/django.wsgi'.
[Tue Dec 21 11:36:33 2010] [error] [client 1.53.149.114] Premature end of script headers: django.wsgi
[Tue Dec 21 11:36:33 2010] [notice] child pid 24831 exit signal Segmentation fault (11)
[Tue Dec 21 11:36:33 2010] [info] mod_wsgi (pid=24980): Attach interpreter ''.

My conf file:

WSGISocketPrefix /tmp/wsgi

<VirtualHost *:80>
   ServerName mysite.com
   ServerAlias www.mysite.com
   ServerAdmin [email protected]

   DocumentRoot /home/anhtran/webapps/mysite.com/public_html

   WSGIDaemonProcess mysite processes=5 threads=25
   WSGIProcessGroup mysite
   WSGIScriptAlias / /home/anhtran/webapps/mysite.com/django.wsgi

   LogLevel debug

   <Directory /home/anhtran/webapps/mysite.com/mysite>
      Order allow,deny
      Allow from all
   </Directory>

</VirtualHost>

Django works fine in a basic project without a data connection such as MySQLdb or sqlite3. I'm using CentOS 5 64 bit, apache 2.x, mod_wsgi 3.2. I think this is not a problem of Django, but I have no idea for it. Everybody can fix it? Help me. Thanks! :)

django.wsgi

#!/usr/local/bin/python
import os, site, sys

# add the virtual environment path
site.addsitedir('/home/anhtran/webapps/mysite.com/env/lib/python2.6/site-packages')
site.addsitedir('/home/anhtran/webapps/mysite.com/mysite')
site.addsitedir('/home/anhtran/webapps/mysite.com')

# fix markdown.py (and potentially others) using stdout
sys.stdout = sys.stderr

#Calculate the path based on the location of the WSGI script.
project = os.path.dirname(__file__)
workspace = os.path.dirname(project)
sys.path.append(workspace)

os.environ['PYTHON_EGG_CACHE'] = '/home/anhtran/webapps/mysite.com/.python-eggs'
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

I've read some questions in this link: http://code.google.com/p/modwsgi/wiki/FrequentlyAskedQuestions But I still don't understand the solutions.

like image 724
anhtran Avatar asked Dec 21 '10 16:12

anhtran


3 Answers

The daemon process crashed. See comments in the mod_wsgi FAQ about what causes crashes:

http://code.google.com/p/modwsgi/wiki/FrequentlyAskedQuestions

and follow links there.

Ultimately the cause can be many things, including loading incompatible mod_python at same time, using Python C extension module that doesn't work with sub interpreters, incompatible shared library versions used by Apache and/or extension modules in PHP etc.

like image 71
Graham Dumpleton Avatar answered Nov 19 '22 13:11

Graham Dumpleton


Finally, I found the solution. It's a problem of Multiple Python Versions: http://code.google.com/p/modwsgi/wiki/InstallationIssues#Multiple_Python_Versions.

Thanks all! :P

like image 41
anhtran Avatar answered Nov 19 '22 14:11

anhtran


I had a similar problem on django,apache2,mod_wsgi,python2.6 installed on a virtual machine. I solved the problem incerasing the ram assigned to the virtual machine.

I hope this will help.

like image 34
Andrea Araldo Avatar answered Nov 19 '22 13:11

Andrea Araldo