Django Apache FastCGI 重启

发布于 2024-10-19 06:06:33 字数 1723 浏览 0 评论 0原文

根据 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 不起作用?

According to Django docs Django can be configured with FastCGI.

Here's our setup (note that I don't control Apache setup at my workplace and I'm required to use FastCGI since we already have it, rather than install WSGI):

The fcgi-relevant part of our apache conf is:

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

The last line should be most relevant. My django.fcgi is:

#!/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")

According to

http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#restarting-the-spawned-server

restarting the fcgi should be as simple as

touch django.fcgi

but for us it doesn't result in a restart (which is why I'm writing the pid's to files).

Why doesn't the touch django.fcgi work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哑剧 2024-10-26 06:06:33

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

只需在任意本地主机端口(例如 50000)上运行 django,然后执行以下操作:

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

它所需要的只是标准的 mod_rewrite 和 mod_proxy。

I don't know, but I can propose an alternate solution that doesn't involve installing anything:

Just run django on some arbitrary localhost port (say 50000), and then do this:

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

All it requires are the standard mod_rewrite and mod_proxy.

雨的味道风的声音 2024-10-26 06:06:33

好吧,那么,对你的问题进行实际的回答。 :)

看起来你缺少一个选项。

-自动更新(无)

使mod_fastcgi检查应用程序的修改时间
在处理每个请求之前在磁盘上。如果磁盘上的应用程序已更改,则会通知进程管理器并终止该应用程序的所有正在运行的实例。一般来说,最好将这种类型的功能内置到应用程序中(例如,每第 100 个请求,它都会检查磁盘上是否有更新的版本,如果有则退出)。当此选项与 -restart 一起使用时,可能会出现一个突出的问题(bug)。

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

Okay, an actual answer to your question, then. :)

Looks like you're missing an option.

-autoUpdate (none)

Causes mod_fastcgi to check the modification time of the application
on disk before processing each request. If the application on disk has been changed, the process manager is notified and all running instances of the application are killed off. In general, it's preferred that this type of functionality be built-in to the application (e.g. every 100th request it checks to see if there's a newer version on disk and exits if so). There may be an outstanding problem (bug) when this option is used with -restart.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文