All http(s) request are working fine but whenever I try to make a websocket connection it results in the following:
Request URL: https://my-domain.com/ws/listen?jwt=<token>
Request Method: GET
Status Code: 404 Not Found
This is my project configuration:
nginx
upstream geej_app_server {
server unix:/webapp/run/gunicorn.sock fail_timeout=0;
}
server {
server_name my-domain.com;
access_log /webapp/logs/access.log;
error_log /webapp/logs/error.log;
location /static/ {
alias /webapp/geej_backend/static/;
}
location /media/ {
alias /webapp/geej_backend/media/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass https://geej_app_server;
}
}
location /ws/ {
proxy_pass https://geej_app_server;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/ssl/cert.pem;
ssl_certificate_key /etc/ssl/key.pem;
ssl_client_certificate /etc/ssl/cloudflare.crt;
ssl_verify_client on;
}
server {
listen 80;
listen [::]:80;
server_name my-domain.com;
return 302 https://$server_name$request_uri;
}
supervisor
[program:geej]
command = /webapp/env/bin/gunicorn_start
user = guser
stdout_logfile = /webapp/logs/supervisor.log
redirect_stderr = true
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8
gunicorn_start (bash file for starting)
#!/bin/sh
NAME='geej'
DJANGODIR=/webapp/geej_backend
SOCKFILE=/webapp/run/gunicorn.sock
USER=geejuser
GROUP=webapp
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=geej.settings
DJANGO_ASGI_MODULE=geej.asgi
TIMEOUT=120
cd $DJANGODIR
source ../env/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mdkir -p $RUNDIR
exec ../env/bin/gunicorn -k uvicorn.workers.UvicornWorker ${DJANGO_ASGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--timeout $TIMEOUT \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
routing.py
# chat/routing.py
from django.urls import re_path
from . import consumers
websocket_urlpatterns = [
re_path(r"ws/listen", consumers.TaskConsumer.as_asgi()),
]
> ufw status
To Action From
-- ------ ----
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere ALLOW ---- (censored) ---- # Cloudflare IP
22/tcp ALLOW Anywhere
Anywhere (v6) ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere (v6) ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere (v6) ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere (v6) ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere (v6) ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere (v6) ALLOW ---- (censored) ---- # Cloudflare IP
Anywhere (v6) ALLOW ---- (censored) ---- # Cloudflare IP
22/tcp (v6) ALLOW Anywhere (v6)