如何配置 Apache 在 Django Channels 中运行 ASGI?Apache 甚至是必需的吗? [英] How to configure Apache to run ASGI in Django Channels? Is Apache even required?

查看:17
本文介绍了如何配置 Apache 在 Django Channels 中运行 ASGI?Apache 甚至是必需的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个 django 项目并使用 Apache-WSGI 组合将其部署到生产环境中.为此,我添加了apache2.conf如下图:

I built a django-project and deployed it to production using Apache-WSGI combo. For that I had added the apache2.conf as shown below:

WSGIScriptAlias / /home/ubuntu/MyProject/MyProject/wsgi.py
WSGIPythonPath /home/ubuntu/MyProject

<Directory /home/ubuntu/MyProject/MyProject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

所以这意味着并非所有对我网站的请求都首先转到 Apache,然后允许 WSGI 发挥作用.因此,如果我关闭 Apache,该网站将无法运行.

So this mean't all requests to my website first go to Apache, which then allows WSGI to come into play. So if I would switch off Apache, the website would not work.

我现在已经安装了 Django-Channels.根据文档中的部署"部分(https://channels.readthedocs.io/en/latest/deploying.html),我有:

I have now installed Django-Channels. As per the 'Deploying' section in the documentation (https://channels.readthedocs.io/en/latest/deploying.html), I have:

  1. 已安装 Redis(在我的 Django 项目服务器上)
  2. 运行工作服务器
  3. 运行 Daphne(接口服务器)
  4. 我目前已停止 Apache,但该网站拒绝连接.

推荐答案

正如 Lukasa 提到的,我停止了 Apache 服务器,这首先阻止了我的 django 应用程序向全世界交付.然后我运行了以下命令:

As mentioned by Lukasa, I stopped the Apache server, which at first stopped my django app getting delivered out to the world. Then I ran the following commands:

sudo daphne MyProject.asgi:channel_layer --port 80 --bind 0.0.0.0 -v2
sudo python manage.py runworker -v2

这两个命令开始将应用程序交付给来自服务器外部的 http 请求.除了问题帖子中提到的之外,不需要其他配置.

The two commands started delivering the app to http requests from outside the server. No other configurations were required other than mentioned in the question post.

这篇关于如何配置 Apache 在 Django Channels 中运行 ASGI?Apache 甚至是必需的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆