Apache2 + mod_wsgi + Django的Websocket连接

时间:2017-07-27 23:40:15

标签: python django apache ubuntu mod-wsgi

我正在使用mod_wsgi在apache2上部署django项目。 我可以确认从apache2服务器看到Django的页面,但websocket无法连接, 我认为Django-channels不是以apache2开头的。

所以我解决了这个问题,安装'asgi_redis'来启动Django-channels。

'pip3 instal asgi_redis'

我更改了频道图层。

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "asgi_redis.RedisChannelLayer",
            "CONFIG": {
            "hosts": [("localhost", 6379)],
             },
            "ROUTING": "mysite.routing.channel_routing",
    },
}

我尝试了以下命令。

'python3 manage.py runworker'

但发生了以下错误。

2017-07-27 08:07:59,660 - INFO - runworker - Using single-threaded worker.
2017-07-27 08:07:59,661 - INFO - runworker - Running worker against channel 
layer default (asgi_redis.core.RedisChannelLayer)
2017-07-27 08:07:59,663 - INFO - worker - Listening on channels 
http.request, websocket.connect, websocket.disconnect, websocket.receive
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 439, in connect
    sock = self._connect()
 File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 494, in _connect
raise err
File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 482, in _connect
sock.connect(socket_address)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/redis/client.py", line 572, in execute_command
connection.send_command(*args)
File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 538, in send_packed_command
self.connect()
File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. 
Connection refused.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 439, in connect
sock = self._connect()
File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 494,in _connect
raise err
File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 482, 
in _connect
sock.connect(socket_address)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 24, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/dist-packages/channels/management/commands/runworker.py", line 83, in handle
worker.run()
File "/usr/local/lib/python3.5/dist-packages/channels/worker.py", line 87, in run
channel, content = self.channel_layer.receive_many(channels, block=True)
File "/usr/local/lib/python3.5/dist-packages/asgiref/base_layer.py", line 43, in receive_many
return self.receive(channels, block)
File "/usr/local/lib/python3.5/dist-packages/asgi_redis/core.py", line 215, in receive
result = connection.blpop(list_names, timeout=self.blpop_timeout)
File "/usr/local/lib/python3.5/dist-packages/redis/client.py", line 1163, in blpop
return self.execute_command('BLPOP', *keys)
File "/usr/local/lib/python3.5/dist-packages/redis/client.py", line 578, in execute_command
connection.send_command(*args)
File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 563, 
in send_command
self.send_packed_command(self.pack_command(*args))
File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 538, 
in send_packed_command
self.connect()
File "/usr/local/lib/python3.5/dist-packages/redis/connection.py", line 442, 
in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.

需要帮助解决此错误。

Raspberry Pi 3 Ubuntu 16.04.2 Django 1.11.1 Apache2 2.4.18

0 个答案:

没有答案