【问题标题】:WebSocket opening handshake timed out in httpshttps中的WebSocket打开握手超时
【发布时间】:2019-11-04 02:42:26
【问题描述】:

与“wss://ip_address:8008/ws/events?subscribe-broadcast”的 WebSocket 连接失败:WebSocket 打开握手超时

只有在 HTTPS 中打开 UI 时才会超时,在 HTTP 中它的工作...

我已经在 ubuntu 中使用 OpenSSL 生成了证书

我的uwsgi配置是

socket = /tmp/uwsgi.sock   
chmod-socket = 666  
socket-timeout = 60 
chdir = <django path>
wsgi-file  = <django_path>/wsgi.py
virtualenv = <path_to_virtualenv>
vacuum = true
enable-threads  = true
threads=500
startup-timeout = 15
graceful-timeout = 15
http-socket=<my_ip>:8008
http-websockets=true

我的nginx配置是

server {
listen <ip>:80 default;
listen <ip>:443 ssl http2 default_server;
ssl_certificate <path>/generate_crt.crt;
ssl_certificate_key <path>/generated_key.key;
client_body_buffer_size 500M;
client_body_timeout 300s;
keepalive_timeout 5000;
client_max_body_size 700M;
access_log syslog:server=unix:/dev/log;
root /tmp/MVM_APPS/angularjs/dist;
index index.html index.htm;
server_name localhost;
location /api {
uwsgi_pass unix:///tmp/uwsgi.sock;
    include uwsgi_params;
    uwsgi_read_timeout 120;
    uwsgi_send_timeout 1000;
}
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_pass http://<ip>:8008;
proxy_read_timeout 86400;
}
location /static {
    alias /<path>/static;
}
location / {
    try_files $uri $uri/ /index.html;
}
}

我正在使用带有 WS4redis 包的 Django。

【问题讨论】:

  • 哇,这拯救了我的一天...... ;-)

标签: django ssl nginx websocket uwsgi


【解决方案1】:

为了让 web-sockets 在 Tls(wss) 协议上工作,您需要生成 ssl 证书,在生成证书后将以下行添加到 uwsgi.ini 文件中。

https-socket=[ip]:[port], /path_to_server_certificate, /path_to_key

并重新启动服务器(您也可以选择再传递 2 个字段 [,ciphers,ca]) 更多详情请见here

或者,如果您的消息代理有能力,您可以使用 Mqtt 或 Stomp 等消息传递协议直接将其公开给客户端

【讨论】:

  • 哇,试试看,让你知道更新... ;-)
猜你喜欢
  • 1970-01-01
  • 2019-12-22
  • 1970-01-01
  • 2023-03-05
  • 2019-06-11
  • 1970-01-01
  • 2017-03-19
  • 1970-01-01
  • 2023-03-08
相关资源
最近更新 更多