Django通道使用redis-server和nginx

问题描述 投票:0回答:1

我一直在关注这个http://channels.readthedocs.io/en/latest/getting-started.html

我目前的设置(添加频道之前)是nginx,uwsgi,django。

在我的本地,我在一个转发端口5000的流浪盒上运行所有这些 Django服务器目前运行在0.0.0.0:5000 我的nginx配置监听8000并提供静态文件 它也有:

location / {
    include uwsgi_params;
    uwsgi_pass unix:{{backend_uwsgi_socket}};
}

在学习本教程之后,一切正常,直到我从更改我的settings.py开始

CHANNEL_LAYERS = {
  "default": {        
    "BACKEND": "asgiref.inmemory.ChannelLayer",        
    "ROUTING": "myapp.routing.channel_routing",
  },
}

CHANNEL_LAYERS = {
 "default": {
    "BACKEND": "asgi_redis.RedisChannelLayer",        
    "CONFIG": {
        #"hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
        #"hosts": [("redis-server-name", 6379)],           
        "hosts": [("localhost", 6379)],
    },
    "ROUTING": "myapp.routing.channel_routing",
 },
}

所以教程说要安装redis-server,然后再次运行命令: manage.py runserver 0.0.0.0:80000

如果我关闭nginx,并运行它投诉:

ConnectionError:错误111连接到localhost:6379。拒绝连接。

我尝试在我的nginx服务器块中为这个端口添加一个监听器,然后我得到以下错误:

^ Cvagrant @ vagrant-ubuntu-trusty-64:/ srv / myproj / backend $ sudo python manage.py runserver 0.0.0.0:8000 执行系统检查...... 系统检查未发现任何问题(0静音)。 2017年12月28日 - 17:10:25 Django版本1.10,使用设置'backend.settings' 在http://0.0.0.0:8000/启动Channels开发服务器 通道层默认(asgi_redis.core.RedisChannelLayer) 使用CONTROL-C退出服务器。 2017-12-28 17:10:25,883 - INFO - worker - 听取频道http.request,websocket.connect,websocket.disconnect,websocket.receive 线程Thread-1中的异常: Traceback(最近一次调用最后一次): 在__bootstrap_inner中输入文件“/usr/lib/python2.7/threading.py”,第810行 self.run() 运行文件“/usr/local/lib/python2.7/dist-packages/channels/management/commands/runserver.py”,第176行 worker.run() 运行文件“/usr/local/lib/python2.7/dist-packages/channels/worker.py”,第87行 channel,content = self.channel_layer.receive_many(channels,block = True) 在receive_many中输入文件“/usr/local/lib/python2.7/dist-packages/asgiref/base_layer.py”,第43行 返回self.receive(频道,块) 文件“/usr/local/lib/python2.7/dist-packages/asgi_redis/core.py”,第168行,收到 result = connection.blpop(list_names,timeout = self.blpop_timeout) 文件“/usr/local/lib/python2.7/dist-packages/redis/client.py”,第1269行,在blpop中 return self.execute_command('BLPOP',* keys) 在execute_command中输入文件“/usr/local/lib/python2.7/dist-packages/redis/client.py”,第668行 return self.parse_response(connection,command_name,** options) 在parse_response中输入文件“/usr/local/lib/python2.7/dist-packages/redis/client.py”,第680行 response = connection.read_response() 在read_response中输入文件“/usr/local/lib/python2.7/dist-packages/redis/connection.py”,第624行 response = self._parser.read_response() 在read_response中输入文件“/usr/local/lib/python2.7/dist-packages/redis/connection.py”,第292行 (str(byte),str(response))) InvalidResponse:协议错误:<,html>

打印完毕后,它会不断打印以下信息:

错误 - 服务器 - 尝试接收消息时出错:协议错误:<,html>

我正在努力为此寻找答案,并在一些不同的教程/示例后让自己感到困惑。 我知道这将是我错过了一些明显的东西,或者是误解了一些东西。

任何指针或帮助将不胜感激。

django nginx redis django-channels
1个回答
0
投票

ConnectionError:错误111连接到localhost:6379。拒绝连接。

6379是应该运行redis服务器的端口。你不应该配置nginx来监听它。

您发布的堆栈跟踪意味着django服务器正在尝试连接到redis(端口6379)并且它不喜欢响应(因为nginx在那里监听,而不是redis)。

© www.soinside.com 2019 - 2024. All rights reserved.