Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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.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.

share|improve this question
What do the logs say? – Dennis Williamson Feb 26 '10 at 22:07
@Dennis, I wish I knew what the logs said. They are off limites. – Jim Mar 2 '10 at 20:16

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. ;-)

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.

share|improve this answer


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.

share|improve this answer
AddHandler fastcgi-script .fcgi

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.