我试图使用Nginx在AWS ubuntu os中使用Django通道部署Django应用程序。我在Nginx中配置了Django服务器。但我不知道如何在Nginx中配置通道或Redis服务器。
我的nginx配置如下:
server {
listen 80;
server_name 52.77.215.218;
location / {
include proxy_params;
proxy_pass http://localhost:8000/
}
}我的settings.py:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("127.0.0.1", 6379)],
},
},
}我的requirements.txt:
aioredis==1.3.1
asgiref==3.5.2
async-timeout==4.0.2
attrs==22.1.0
autobahn==22.7.1
Automat==20.2.0
certifi==2022.6.15
cffi==1.15.1
channels==3.0.5
channels-redis==2.4.2
charset-normalizer==2.1.1
constantly==15.1.0
coreapi==2.3.3
coreschema==0.0.4
cryptography==37.0.4
daphne==3.0.2
defusedxml==0.7.1
Django==4.1
django-cors-headers==3.13.0
django-templated-mail==1.1.1
djangorestframework==3.13.1
djangorestframework-simplejwt==4.8.0
djoser==2.1.0
gunicorn==20.1.0
hiredis==2.0.0
hyperlink==21.0.0
idna==3.3
incremental==21.3.0
itypes==1.2.0
Jinja2==3.1.2
MarkupSafe==2.1.1
msgpack==0.6.2
mysql==0.0.3
mysqlclient==2.1.1
oauthlib==3.2.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
PyJWT==2.4.0
pyOpenSSL==22.0.0
python3-openid==3.2.0
pytz==2022.2.1
requests==2.28.1
requests-oauthlib==1.3.1
service-identity==21.1.0
six==1.16.0
social-auth-app-django==4.0.0
social-auth-core==4.3.0
sqlparse==0.4.2
Twisted==22.4.0
twisted-iocpsupport==1.0.2
txaio==22.2.1
typing_extensions==4.3.0
tzdata==2022.2
uritemplate==4.1.1
urllib3==1.26.12
zope.interface==5.4.0当我使用python3 manage.py runserver 0.0.0.0:8000服务器运行服务器时,运行良好并与redis服务器连接,但当我使用gunicorn app.wsgi -b 0.0.0.0:800运行服务器时,就无法连接到webbsocket。
我也尝试过Hostinger VPS,但问题是一样的。
发布于 2022-08-31 06:15:40
你需要下载达芙妮。
Daphne是一个用于Django通道的高性能websocket服务器。
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/daphne/
https://github.com/django/daphne
https://channels.readthedocs.io/en/stable/deploying.html
如何运行达芙妮:daphne -b 0.0.0.0 -p 8070 django_project.asgi:application
这是我的Nginx频道:
upstream django {
server 127.0.0.1:8080;
}
upstream websockets{
server 127.0.0.1:8070;
}
server {
...
...
location /ws {
proxy_pass http://websockets;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
...
}
location / {
proxy_pass http://django;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $remote_addr;
...
}
}https://stackoverflow.com/questions/73551471
复制相似问题