Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

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
add comment

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.