1

I am running a ec2 instance to host some Django websites. The websites are being served by Apache with the use of mod_wsgi

Since a few days I am trying to deploy a new webplatform we are developing but I am running into a problem that seems impossible for me to solve. For security reasons we use scrypt 0.4 to secure the users personal information like passwords.

On the development server everything works like a charm but when we deploy to our live server we get a 500 Internal Server error. The apache log gives me the following message

Premature end of script headers: socialmarketingplatform.wsgi, referer:

When I uncomment the line where the scrypt module is used everything works fine. Also when I run the server delivered with Django with scrypt enabled everything works on the live server. So it is a combination of mod_wsgi, django and scrypt that generates the error.

I am using the following wsgi file:

import os
import sys

path = '/var/www/vhosts/[sub_domain]'
if path not in sys.path:
    sys.path.append(path)
sys.path.append(path + '/socialmarketingplatform')
os.environ['DJANGO_SETTINGS_MODULE'] = 'socialmarketingplatform.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

And the following virtualhost config:

<VirtualHost *:80>
    #Basic setup
    ServerAdmin [removed email]
    ServerName luxdevelopment.net
    ServerAlias [sub domain]
    DocumentRoot /var/www/vhosts/[sub domain]/socialmarketingplatform/

    Alias /media/admin /usr/lib/python2.6/site-packages/Django-1.3-py2.6.egg/django/contrib/admin/media
    Alias /media /var/www/vhosts/[sub domain]/socialmarketingplatform/media
    <Location media="">
        SetHandler None
    </Location>

    LogLevel warn
    ErrorLog  /var/log/httpd/smp_error.log
    CustomLog /var/log/httpd/smp_access.log combined

    WSGIDaemonProcess luxdevelopment.net user=apache group=apache threads=25
    WSGIProcessGroup luxdevelopment.net

    WSGIScriptAlias / /var/www/cgi-bin/socialmarketingplatform.wsgi
</VirtualHost>

I hope someone can help me with this problem. If there are any further question let me know.

René Lux
  • 11
  • 2
  • Argh! Don't put your code in your DocumentRoot! Especially if you're concerned about security. – Daniel Roseman Apr 05 '11 at 13:05
  • @daniel-roseman: That is why my document root is /var/www/html/ if that isn't secure enough yet what do you suggest? Maybe I mis-understood you there I will see if I can move the source outside of that folder. Thanks for your suggestion. – René Lux Apr 05 '11 at 13:14
  • Well what I mean is that you set DocumentRoot to the location of your code, in the vhost config. Don't do that. – Daniel Roseman Apr 05 '11 at 13:35
  • @daniel-roseman: okeuh, thanks for your suggestion will change that later. I first want to fix this error. Before I mix up things. – René Lux Apr 05 '11 at 13:48
  • Just curious, have you perhaps found a solution yourself to this, that you could share back here? I'm guessing the problem arises from SCrypt being a C extension, not Python code. Is there a answer on the mod_wsgi mailing lists perhaps? –  Apr 18 '11 at 22:28
  • Nope no solution yet, I had to fix this problem so I moved to use bcrypt as the encryption method. Still hope that someone can find a better solution later. But for now I had to give up. – René Lux Apr 19 '11 at 12:58

1 Answers1

0

See:

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

The message 'premature end of script headers' is usually indicative of your code crashing the daemon process. You can verify this by looking for segmentation fault or similar message in main Apache error log file. If you enable 'LogLevel info' in main Apache config and VirtualHost then mod_wsgi will log more about daemon process restarts.

A quick remedy if running only application in that daemon process group is to add:

WSGIApplicationGroup %{GLOBAL}

This will work around crashes caused by broken third party extension modules for Python which aren't written properly to work in sub interpreters.

Other than that, can be shared library version mismatches as described in the FAQ.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134