Can't connect to Django Channels virtual server on Ubuntu
I want to deploy Django channels with gunicorn and nginx: this is my codes:
gunicorn.service:
[Unit]
Description=Gunicorn instance to serve mysite
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/root/mysite
ExecStart=/root/apiKomarket/venv/bin/daphne -u /run/mysite.sock
mysite.asgi:application -b 127.0.0.1 -p 8002
[Install]
WantedBy=multi-user.target
nginx:
server {
listen 80;
server_name komarket.net;
location / {
proxy_pass http://unix:/run/mysite.sock;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
asgi.py:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
application = ProtocolTypeRouter({
"http": get_asgi_application(),
"websocket": AuthMiddlewareStack(
URLRouter(websocket_urlpatterns)),
})
router.py:
websocket_urlpatterns = [
path("ws/order/", mycunsomer.as_asgi()),
]
consumer.py:
class mycunsomer(WebsocketConsumer):
def connect(self):
self.accept()
def disconnect(self, close_code):
pass
def receive(self, text_data=None, bytes_data=None):
pass
home.html:
const chatSocket = new WebSocket(
'ws://'
+ window.location.host
+ '/ws/order/'
);
but this codes rais this error:
Traceback (most recent call last):
File "/root/apiKomarket/venv/lib/python3.10/site-packages/django/template/base.py", line 906, in _resolve_lookup
raise VariableDoesNotExist(
django.template.base.VariableDoesNotExist: Failed lookup for key [name] in <URLResolver <module 'API.urls' from '/root/apiKomarket/./API/urls.py'> (None:None) 'apis/'>
Not Found: /favicon.ico