Django Apache FastCGI重启

问题描述:

根据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工作?

我不知道,但我可以建议不涉及安装任何一个替代的解决方案:

一些任意本地主机端口(说50000)上只要运行Django的,然后这样做:

RewriteEngine On 
RewriteRule ^(.*)$ http://localhost:50000/$1 [P] 

它只需要标准的mod_rewrite和mod_proxy。

+1

这可能是发展的美好,但它不适合生产。 Django服务器一次只处理一个请求。 – kmt 2011-02-23 00:02:18

好的,那么你的问题的实际答案。 :)

看起来像你缺少一个选项。

-autoUpdate(无)

成因的mod_fastcgi处理每个请求之前检查应用 的修改时间在磁盘上。如果磁盘上的应用程序已被更改,则会通知进程管理器,并且应用程序的所有正在运行的实例都将被关闭。一般而言,最好将这种类型的功能内置到应用程序中(例如,每检查一次它检查的磁盘上是否有较新的版本,如果存在则退出)。当此选项与-restart一起使用时,可能存在未解决的问题(错误)。

- http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiConfig

+0

谢谢,但我有些怀疑这是*答案。这种杀戮究竟发生了什么?它优美吗?是否等待任何正在进行的请求得到完全满足(即等待响应)。 – kmt 2011-02-24 02:48:49

+0

听起来好像根本不是很优雅。但它确实解释了你必须做的事情,让'touch django.fcgi'重新启动你的应用程序。我没有设计它,我只是回答你的问题。就像我在其他答案中所说的,我认为你最好通过你选择的python wsgi服务器运行django,并使用mod_proxy。但是你似乎不想尝试任何东西,所以...祝你好运? – tangentstorm 2011-02-24 03:43:24