Django_Socketio 和 Apache
我对网络开发还很陌生。最近我一直在使用 Django 制作一个网站。我对在网站中实现 websockets 非常感兴趣。为了实现这一点,我使用了 django-socketio (可在 git hub 上找到 https://github.com/stephenmcd/ django-socketio)。使用 django-socketio 文档中建议的 gevent 的 pywsgi 服务器,所有这一切都工作得很好。
通过阅读一些关于 django 的书籍,似乎建议使用 Django 与 Apache 和 mod_python 进行部署。目前我不确定将 Django、Apache 和 websockets 结合在一起的最佳方法。我应该使用 pywsgi 服务器来处理与 apache 一起运行的 django-socketio 套接字来为项目的其余部分提供服务吗?有没有一种方法可以让 Apache 处理所有事情?我应该不使用 Django-Socketio 吗?我真的很想使用 Django 和 Apache,因为我对它们有一点了解。这比我对其他任何事情的了解要多得多:D
无论如何,我的问题是是否有人知道有关使用 Django-socketio 和 Apache 的任何好的文章或文档,以便我能够了解该主题?
谢谢。
I'm pretty new to web development. Lately I have been making a site using Django. I was very interested in implementing websockets in the site. To achieve this I was using django-socketio (available on git hub at https://github.com/stephenmcd/django-socketio). All this was working fine using gevent's pywsgi server which is suggested in the django-socketio documents.
From reading some books on django it seems that it is recommend to use Django with Apache and mod_python for deployment. At the moment I am unsure of the best way to go about bringing Django, Apache and websockets together. Should I be using the pywsgi server to handle the django-socketio sockets running along side apache to serve the rest of the project? Is there a way in which Apache can handle everything? Should I just not use Django-Socketio? I would really like to use Django and Apache because I know a little about them. Which is a lot more than I know about anything else :D
Anyway my question is really if anybody knows any good articles or documentation on using Django-socketio and Apache so I can get my head around the topic?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您读到的任何暗示 mod_python 的内容都已经过时了。它已不再开发,mod_wsgi 是使用 Apache 时的正确方法。
据我所知,mod_wsgi 不支持 WebSockets 所需的打开连接类型。在 Google 上的快速搜索显示,有多种方法可以让 WebSocket 在 Apache 下工作,但是您需要研究一下它与 gevent/django-socketio 堆栈的配合效果如何。
我建议按照我在 django-socketio 文档中推荐的方式使用 gevent 的服务器来处理 WebSocket 连接。基准测试应该持保留态度,但是如果您看一下这些结果 你会发现 gevent 与 mod_wsgi 相当。
django-socketio 提供了便利,让您可以通过单个应用程序实例提供 WebSocket 连接以及常规 Django 视图。如果这不适合您,您可以将它们实现为单独的项目,并在 Apache/mod_wsgi 下运行常规 Django 部分。
To start with, anything you read suggesting mod_python is highly out-dated. It's no longer developed and mod_wsgi is the right approach when using Apache.
As far as I'm aware, mod_wsgi doesn't support the type of open connections required by WebSockets. A quick search on Google shows that there are ways to get WebSockets working under Apache, but as to how well that would work with the gevent/django-socketio stack is something you'd need to look into.
I would suggest using gevent's server as I recommended in the django-socketio docs, for handling the WebSocket connections. Benchmarks should be taken with a grain of salt, but if you take a look at these results you'll find gevent to be on par with mod_wsgi.
django-socketio provides the convenience of letting you serve the WebSocket connections as well as regular Django views through a single application instance. If that doesn't suit you, you could implement these as separate projects, and run the regular Django part under Apache/mod_wsgi.