websockets django nginx webssh

websocketpython

1.實現方案一:nginx

  django + dwebsocket    + gunicorn +nginxweb

  pip install dwebsocketdjango

  部分代碼vim

  

from dwebsocket import require_websocket

@require_websocket
def ws(request):
    if not request.is_websocket():                 # 判斷是否是websocket鏈接
        pass
    else:
        多線程
        while request.websocket.has_messages:
            msg= request.websocket.wait()
            if msg:
               。。。

接受方法
。。。
req.websocket.send(data)

  

 

       設置 gunicorn 的timeout 解決30秒退出websocket

  nohub gunicorn -w 6 -b 127.0.0.1:8080 --timeout 3600&多線程

 

  nginx.confapp

server{
    # the port your site will be served on
    listen      80;

    # the domain name it will serve for
    #server_name www.scloud.cn; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /opt/soft/pro_name/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /opt/soft/pro_name/static; # your Django project's static files - amend as required
    }

    location / {
      # 反向代理透傳客戶端ip
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://localhost:8080;
    }

     #websocket setting
     location /app/websocket_url {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        client_max_body_size 10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 600;
        proxy_send_timeout 120;
        proxy_read_timeout 600;
        proxy_buffer_size 4k;
        proxy_buffers 4 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
     }

}

  

2.實現方案二:dom

  django +uwsgi + nginxssh

       import uwsgi

       uwsgi.websocket_recv_nb() 

       會爆出異常 no Pone   until 30 seconds

       解決方案: 1.修改uwsgi 源碼 : 在初始化中將默認的30秒改大,或者註釋掉check_ping_pong 方法

        2.誤打誤撞不知道修改了什麼,解決了,可是很遺憾,我忘記了本身作了什麼

                     暫時還沒弄懂爲何發了ping,沒有響應pong

webssh

     xterm.js

     默認是utf-8 ,最小容器是沒有安裝vim的,使用vim注意解決編碼問題,以及width and  height,編碼有誤會出現閃退問題。 寬和高設置錯誤,會不顯示全屏

相關文章
相關標籤/搜索