首先,这是我的剧本:
#!/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")
正如所描述的here。
这是我在尝试从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()
但我仍然得到完全相同的错误......
答案 0 :(得分:6)
解决了它。无论出于何种原因,这个.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]
答案 1 :(得分:2)
脚本希望这些参数作为环境变量传递。由于它们不在shell环境中,并且脚本没有在apache fastcgi环境(提供它们)中运行,因此它会抱怨。
您是否可以访问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和Django docs上找到进一步的说明。