姜戈 +阿帕奇+ Windows WSGIDaemonProcess 替代方案

发布于 2024-10-15 15:18:41 字数 384 浏览 1 评论 0 原文

设置 django 站点并在开发服务器上运行后,我终于开始考虑使用推荐的 mod_wsgi/apache22 将其部署在生产环境中。我目前仅限于在 Windows XP 计算机上部署它。

我的问题是我编写的几个 django 视图使用 python subprocess 模块在文件系统上运行程序。运行 subprocess.Popen 时我不断收到错误我已经看到了几个询问此问题的问题,接受的答案是使用 WSGIDaemonProcess 来处理问题(由于 apache 用户的权限,我相信)。

唯一的问题是 WSGIDaemonProcess 不适用于 Windows 上的 mod_wsgi。有什么方法可以一起使用 mod_wsgi/apache/windows/subprocess 吗?

After setting up a django site and running on the dev server, I have finally gotten around to figuring out deploying it in a production environment using the recommended mod_wsgi/apache22. I am currently limited to deploying this on a Windows XP machine.

My problem is that several django views I have written use the python subprocess module to run programs on the filesystem. I keep getting errors when running the subprocess.Popen I have seen several SO questions that have asked about this, and the accepted answer is to use WSGIDaemonProcess to handle the problem (due to permissions of the apache user, I believe).

The only problem with this is that WSGIDaemonProcess is not available for mod_wsgi on Windows. Is there any way that I can use mod_wsgi/apache/windows/subprocess together?

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

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

发布评论

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

评论(2

输什么也不输骨气 2024-10-22 15:18:41

无论如何,从 mod_wsgi 中打开子进程并不是一个好主意。

另一种(也是常见的)方法是在 apache 端使用 mod_proxy,并将来自 apache 的请求转发到运行 Django 的 WSGI 服务器。这样做的好处是可以将 python 线程移出 apache 的内存空间 wsgi 服务器有很多选项;龙卷风和gunicorn是两个流行的选择,gunicorn与Django集成*。

*我所说的集成只是指如果您将其添加到 INSTALLED_APPS 中,它会提供一个 manage.py 命令。

It's not a good idea to open subprocesses from within mod_wsgi, anyway.

An alternative (and a common one) is to use mod_proxy on the apache side and forward requests from apache to a WSGI server running Django. This has the advantage of moving the python thread(s) out of apache's memory space There are dozens of options for wsgi servers; tornado and gunicorn are two popular choices, and gunicorn integrates* with Django.

*by integrate I just mean it provides a manage.py command if you add it to INSTALLED_APPS.

悟红尘 2024-10-22 15:18:41

我在尝试在此配置下使用子进程时遇到了几个问题。因为我不确定你具体遇到了什么问题,所以我可以分享一些对我来说不容易解决但事后看来相当微不足道的事情。

  1. 我在尝试执行应用程序时收到与权限相关的错误。我进行了相当多的搜索,但很难找到 Windows 特定的答案。这一点很明显:我将Apache运行的用户更改为具有更高权限的用户。 (请注意,这会带来安全隐患,因此您需要确保了解自己正在了解的内容)。
  2. Django(取决于您的配置)可能会将字符串存储为 Unicode。我有一个命令行应用程序,我试图使用一些从我看来的参数运行,尽管传入了正确的参数,但它还是崩溃了。经过几个小时的挫折,我做了一个 type(args) ,它返回 而不是我期望的字符串。快速转换解决了这个问题。

I ran into a couple of issues trying to use subprocess under this configuration. Since I am not sure what specifically you had trouble with I can share a couple of things that were not easy for me to solve but in hindsight seem pretty trivial.

  1. I was receiving permissions related errors when trying to execute an application. I searched quite a bit but was having a hard time finding Windows specific answers. This one was obvious: I changed the user under which Apache runs to a user with higher permissions. (Note, there are security implications with that so you want to be sure you understand what you are getting in to).
  2. Django (depending on your configuration) may store strings as Unicode. I had a command line application I was trying to run with some parameters from my view which was crashing despite having the correct arguments passed in. After a couple hours of frustration I did a type(args) which returned <type 'unicode'> rather than my expected string. A quick conversion resolved that issue.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文