FastCGI、Apache、Django和500e

2024-06-02 07:19:16 发布

您现在位置:Python中文网/ 问答频道 /正文

Apache和FastCGI有500个内部错误。花了一整天来寻找原因

/etc/apache2/vhost.d/mysite.conf文件

FastCGIExternalServer /home/me/web/mysite.fcgi -socket /home/me/web/mysite.sock
Listen 80
<VirtualHost *:80>
        ServerName os.me #That's my localhost machine
        DocumentRoot /home/me/web
        Alias /media/ /home/me/develop/projects/media

        <Directory "/home/me/web">
                AllowOverride All
                Allow from all
                Order allow,deny
        </Directory>

</VirtualHost>

/主页/me/web/.htaccess

Options +Indexes +FollowSymlinks
AddHandler fastcgi-script .fcgi

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

/主页/me/web/mysite.fcgi

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

os.chdir("/home/me/develop/projects/mysite")
os.environ['DJANGO_SETTINGS_MODULE'] = "mysite.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded",daemonize="false")

/var/log/apache2/错误日志

...    
[Sat Aug 07 01:41:13 2010] [error] [client 127.0.0.1] (2)No such file or directory: FastCGI: failed to connect to server "/home/me/web/mysite.fcgi": connect() failed
[Sat Aug 07 01:41:13 2010] [error] [client 127.0.0.1] FastCGI: incomplete headers (0 bytes) received from server "/home/me/web/mysite.fcgi"

执行.fcgi文件(它的工作方式是html页面获得状态“200ok”,并按原样呈现):

me@os ~/web $ python mysite.fcgi 
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 200 OK
Content-Type: text/html
...

Tags: fromwebwsgihomebyserverparamos