首先,这是我的剧本:
#!/usr/bin/python
import sys, os
sys.path.append('/home/username/python')
sys.path.append("/home/username/python/flup")
sys.path.append("/home/username/python/django")
# more path stuff
os.environ['DJANGO_SETTINGS_MODULE'] = "project.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")正如所描述的这里。
下面是我试图从shell运行它时遇到的错误:
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: 404 NOT FOUND
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<!-- more html which looks to be the correct output -->我的问题是,为什么这些参数不是由FastCGI自动传递的?我做错了什么?从我的web服务器运行脚本只会给我一个内部服务器错误。
而不是脚本的最后两行,我可以使用
from flup.server.fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
WSGIServer(WSGIHandler()).run()但我还是犯了同样的错误..。
发布于 2009-04-29 06:22:16
解决了。无论出于什么原因,这个.htaccess文件都起了作用。我发誓我以前试过这些..。
AddHandler fcgid-script .fcgi
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(adminmedia/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(cgi-bin/myproject.fcgi)
RewriteRule ^(.*)$ cgi-bin/myproject.fcgi/$1 [L]发布于 2009-04-29 02:06:27
脚本期望将这些参数作为环境变量传递。由于它们不存在于您的shell环境中,而且脚本也没有在apache环境(提供它们的环境)中运行,所以它会发出抱怨。
您可以访问apache错误日志吗?他们怎么说?
您的主机有mod_wsgi支持吗?如果是这样,您可以使用Django的wsgi处理程序:
import sys
import os
base = os.path.dirname(os.path.abspath(__file__)) + '/..'
sys.path.append(base)
os.environ['DJANGO_SETTINGS_MODULE'] = 'yourproject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()进一步的说明可以在modwsgi wiki和姜戈博士上找到。
https://stackoverflow.com/questions/800584
复制相似问题