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

查看:417
本文介绍了如何配置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. 在我的Django Project服务器上安装了Redis
  2. 运行工作服务器

  3. 运行Daphne(接口服务器)

  4. 此刻我已经停止了Apache,并且停止了网站拒绝连接。

  1. Installed Redis (on my Django Project server)
  2. Run worker servers
  3. Run Daphne (interface server)
  4. I have stopped Apache at the moment and the website refuses to connect.


推荐答案

如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天全站免登陆