根据Django文档,Django可以使用FastCGI进行配置。
下面是我们的设置(注意,我在工作场所并不控制Apache的设置,我需要使用FastCGI,因为我们已经有了它,而不是安装WSGI):
apache conf中与fcgi相关的部分是:
LoadModule fastcgi_module modules/mod_fastcgi.so
# IPC directory location
#
FastCgiIpcDir "/path/to/FastCGI_IPC"
# General CGI config
#
FCGIConfig -idle-timeout 30 -listen-queue-depth 4 -maxProcesses 40 -minProcesses 10 -maxClassProcesses 2 -killInterval 60 -updateInterval 20 -singleThreshhold 0 -multiThreshhold 10 -processSlack 5 -failed-restart-delay 10
# To use FastCGI scripts:
#
AddHandler fastcgi-script .fcg .fcgi .fpl
FastCgiServer "/path/to/my/django.fcgi" -listen-queue-depth 24 -processes 8 -restart-delay 1 -min-server-life 2 -failed-restart-delay 10最后一行应该是最相关的。我的django.fcgi是:
#!/path/to/python-2.5/bin/python
import sys, os
open('pid', "w").write("%d" % (os.getpid()))
# Add a custom Python path.
sys.path.insert(0, "/path/to/django/")
sys.path.insert(0, "/path/to/python2.5/site-packages/")
# Switch to the directory of your project. (Optional.)
os.chdir("/path/to/django/site")
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "site.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")根据
http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#restarting-the-spawned-server
重新启动fcgi应该像下面这样简单:
touch django.fcgi但对我们来说,这并不会导致重新启动(这就是为什么我要将pid写入文件)。
为什么触摸屏django.fcgi不能工作?
发布于 2011-02-23 06:31:55
我不知道,但我可以提出一个不需要安装任何东西的替代解决方案:
只需在任意本地主机端口(比如50000)上运行django,然后执行以下操作:
RewriteEngine On
RewriteRule ^(.*)$ http://localhost:50000/$1 [P]它所需要的只是标准的mod_rewrite和mod_proxy。
发布于 2011-02-23 08:27:11
好的,那就给你一个实际的答案。:)
看起来你错过了一个选择。
-autoUpdate (无)
使mod_fastcgi在处理每个请求之前检查磁盘上应用程序的修改时间。如果磁盘上的应用程序发生了更改,则会通知进程管理器,并终止该应用程序的所有正在运行的实例。一般来说,最好将这种类型的功能内置到应用程序中(例如,每100个请求,它就会检查磁盘上是否有更新的版本,如果有,就退出)。当此选项与-restart一起使用时,可能存在一个突出的问题(错误)。
-- http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiConfig
https://stackoverflow.com/questions/5084507
复制相似问题