首先,这是我的脚本:
#!/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()
但我仍然得到完全相同的错误......