根据Django文档Django可以使用FastCGI进行配置。Django Apache FastCGI重启
这是我们的安装(注意,我不会在我的工作场所控制的Apache设置,我需要使用FastCGI的,因为我们已经拥有了它,而不是安装WSGI):
的FCGI相关的部件我们的apache conf是:
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工作?
这可能是发展的美好,但它不适合生产。 Django服务器一次只处理一个请求。 – kmt 2011-02-23 00:02:18