2

If I browse to my site, I get a 500 "internal server error." However, if I SSH into my server and go to my site's folder and run "python mysite.fcgi" I see the HTML rendered fine. Obviously, something is wrong, but I'm not sure what.

Here is my .htaccess file:

AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(static/.*)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]

Here is my mysite.fcgi file:

#!/usr/bin/python2.5
import sys, os
sys.path.insert(0, "/kunden/homepages/34/[mydir]/htdocs/projects/django")
sys.path.insert(1, "/kunden/homepages/34/[mydir]/lib/python/site-packages")
os.chdir("/kunden/homepages/34/[mydir]/htdocs/projects/django/mysite")
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(["method=threaded", "daemonize=false"])

I'm setting this up on 1and1. It has been a pain, but I think I'm close.

2
  • What do the logs say? Feb 26, 2010 at 22:07
  • @Dennis, I wish I knew what the logs said. They are off limites.
    – Jim
    Mar 2, 2010 at 20:16

3 Answers 3

1

With CGIs a 500 server error is often caused by bad header data being output by your CGI before the HTML code. You should output the content-type and TWO carriage returns "\n" before the html begins. Any unexpected output will cause the 500 error.

I'm not a Python guy so here's a Perl example. ;-)

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";

You may be able to find the exact cause in your server logs. Always check there first when you see 500 errors.

0

Try:

os.environ['PYTHON_EGG_CACHE'] = '/path/to/writeable/folder'

And then chmod 777 that folder.

If you can run it as ssh, and apache is running as www-data (or some UID other than yours), it is possible that it is trying to write to the eggcache and getting a permission denied.

0
AddHandler fastcgi-script .fcgi

<IfModule mod_fcgid.c>
    AddHandler fcgid-script .fcgi
    <Files ~ (\.fcgi)>
        SetHandler fcgid-script
        Options +FollowSymLinks +ExecCGI
    </Files>
</IfModule>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /mysite.fcgi/$1 [QSA,L]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .