The site loads fine, but the channels do not work. In the console, I get: Failed to connect to WebSocket to "ws: //fortests.ovh/8": Error during handshake WebSocket: Unexpected response code: 404
Server: Ubuntu 16.04 on Digital Ocean nginx Version: nginx / 1.10.0 (Ubuntu) Redis v server = 3.2.8
my settings.py:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'asgi_redis.RedisChannelLayer',
'CONFIG': {
'hosts': [('localhost', 6379)],
},
'ROUTING': 'slist.routing.channel_routing',
}
}
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "slist.settings")
application = get_wsgi_application()
consumers.py
import json
from channels import Group
from channels.auth import channel_session_user_from_http, channel_session_user
from .models import Item
@channel_session_user_from_http
def ws_add(message):
message.reply_channel.send({"accept": True})
Group("users").add(message.reply_channel)
routing.py
from channels.routing import route
from tobuy.consumers import ws_add, ws_receive, ws_disconnect
channel_routing = [
route("websocket.connect", ws_add),
route("websocket.receive", ws_receive),
route("websocket.disconnect", ws_disconnect),
]
Js
var socket = new WebSocket('ws://' + window.location.host + '/' + {{ active_list.id }});
Nginx settings
server {
listen 80;
server_name server_name fortests.ovh;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/kuba1/slistproject/slistvenv/src;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/kuba1/slistproject/slistvenv/src/slist.sock;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}