5 websocket一直提示404,以前有老哥说channel版本降低了就可以,我这边降低了也不行,到底什么原因? 6天02时34分26秒

发布于 2025-11-20 11:06:17

后台日志

Nov 20 08:22:45 invxl36483 systemd[1]: Started Service.
Nov 20 08:22:46 invxl36483 python[387791]: [2025-11-20 10:52:46][daphne.cli.run():262] [INFO] Starting server at tcp:port=8000:interface=0.0.0.0
Nov 20 08:22:46 invxl36483 python[387791]: [2025-11-20 10:52:46][daphne.server.run():120] [INFO] HTTP/2 support not enabled (install the http2 and tls Twisted extras)
Nov 20 08:22:46 invxl36483 python[387791]: [2025-11-20 10:52:46][daphne.server.run():129] [INFO] Configuring endpoint tcp:port=8000:interface=0.0.0.0
Nov 20 08:22:46 invxl36483 python[387791]: [2025-11-20 10:52:46][daphne.server.listen_success():160] [INFO] Listening on TCP address 0.0.0.0:8000
Nov 20 08:22:52 invxl36483 python[387791]: [2025-11-20 10:52:52][django.request.log_response():241] [WARNING] Not Found: /ws/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzYzNjkyOTgyLCJpYXQiOjE3NjM2MDY1ODIsImp0aSI6IjkzNjBhOWQ2YmNmOTRlODJiMGJhYWQ0NDAzMzk0MzU3IiwidXNlcl9pZCI6MzcwfQ.BcLKfpmz5UB8jeSJBFPRvnE8cEykjmOGg3JFkVgVZX4/
Nov 20 08:22:58 invxl36483 python[387791]: [2025-11-20 10:52:58][django.request.log_response():241] [WARNING] Not Found: /ws/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzYzNjkyOTgyLCJpYXQiOjE3NjM2MDY1ODIsImp0aSI6IjkzNjBhOWQ2YmNmOTRlODJiMGJhYWQ0NDAzMzk0MzU3IiwidXNlcl9pZCI6MzcwfQ.BcLKfpmz5UB8jeSJBFPRvnE8cEykjmOGg3JFkVgVZX4/

后端部署方式:

daphne -b 0.0.0.0 -p 8000 application.asgi:application

前端:nginx

/etc/nginx/conf.d/web.conf
server {
        listen       8080;
        client_max_body_size 100M;
        server_name  dvadmin-web;
        charset utf-8;
        location / {
            proxy_set_header Host $http_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 https;
            root /data01/opt/web/dist;
            index  index.html index.php index.htm;
            # 禁止缓存html文件,避免前端页面不及时更新,需要用户手动刷新的情况
            if ($request_uri ~* "^/$|^/index.html|^/index.htm") {
                add_header Cache-Control "no-store";
            }
        }
        location = /index {
            return 301 $scheme://$host/#/home;
        }
        # 后端服务
        location /api {
          proxy_http_version 1.1;
          proxy_set_header Host $http_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;
          proxy_set_header X-Nginx-Proxy true;
          # 添加缓存控制头
          add_header Cache-Control "no-cache, no-store, must-revalidate" always;
          add_header Pragma "no-cache" always;
          add_header Expires "0" always;

          set_real_ip_from 0.0.0.0/0;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_connect_timeout 600s;
          proxy_read_timeout 600s;
          proxy_send_timeout 600s;
          real_ip_header X-Forwarded-For;
          rewrite ^/api/(.*)$ /$1 break;  #重写
          proxy_pass http://127.0.0.1:8000/;

        }
        # Django media
        location /media  {
            root /opt/project/backend;  # your Django project's media files - amend as required
        }
        # Django static
        location /static {
            root /opt/project/backend; # your Django project's static files - amend as required
        }
        #禁止访问的文件或目录
        location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
        {
            return 404;
        }

    }

backendapplicationrouting.py

from django.urls import path
from application.websocketConfig import MegCenter

websocket_urlpatterns = [
    path('ws/<str:service_uid>/', MegCenter.as_asgi()),  # consumers.DvadminWebSocket 是该路由的消费者
]

查看更多

关注者
0
被浏览
36
0 个回答
暂无答案,快来添加答案吧

撰写答案 当前问题悬赏金额为¥5 元,被提问者采纳后将获得赏金

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览