首页 > 解决方案 > Django 频道使用 ws:// 但无法与 wss:// 握手

问题描述

nginx设置

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name www.sample.co;
    return 301 https://$host$request_uri;
}
server {
    ssl on;
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name www.sample.co;
    rewrite ^(.*) https://beta.sample.co$1 permanent;
    ssl_certificate /home/ubuntu/certificate/certificate.crt;
    ssl_certificate_key /home/ubuntu/certificate/private.key;
    root /var/www/html;
    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;
    server_name _;
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
}

跑在达芙妮上

CMD ["daphne","-b","0.0.0.0","-p","8001","config.asgi:application"]

工作正常

ws://xyz.amazonaws.com/ws/sample/<sample-id>/

无法继续工作

wss://xyz.amazonaws.com/ws/sample/<sample-id>/

错误:

WebSocket 连接到“wss://xyz.amazonaws.com/ws/sample//”失败:连接建立错误:net::ERR_CERT_COMMON_NAME_INVALID

这些应用程序在 AWS 上运行。从 https 调用 WebSocket。我尝试ws://从本地的虚拟反应应用程序调用 WebSocket,它工作正常。

标签: javascriptdjangoamazon-web-serviceswebsocketdjango-channels

解决方案


我启用了限制连接到 websocket 的 CORS 策略。禁用后它对我来说工作正常


推荐阅读