How to use TLS in Play!Framework WebSockets (“wss://”)

后端 未结 4 1636
走了就别回头了
走了就别回头了 2020-12-05 08:51

I cannot use wss:// in my simple WebSocket app created with Play!Framework 2.2. It echoes the message back. The endpoint is like this

def indexW         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 09:07

    I really wanted to figure this out for you! But I didn't like the answer. It appears there's no Play support yet for SSL for websockets. Saw mention of it here and no sign of progress since: http://grokbase.com/t/gg/play-framework/12cd53wst9/2-1-https-and-wss-secure-websocket-clarifications-and-documentation

    However, there's hope! You can use nginx as a secure websocket (wss) endpoint, to forward to a internal play app with a insecure websocket endpoint:

    The page http://siriux.net/2013/06/nginx-and-websockets/ provided this explanation and sample proxy config for nginx:

    Goal: WSS SSL Endpoint: forwards wss|https://ws.example.com to ws|http://ws1.example.com:10080

    "The proxy is also an SSL endpoint for WSS and HTTPS connections. So the clients can use wss:// connections (e.g. from pages served via HTTPS) which work better with broken proxy servers, etc."

    server {
        listen       443;
        server_name  ws.example.com;
    
        ssl on;
        ssl_certificate ws.example.com.bundle.crt;
        ssl_certificate_key ws.example.com.key;
        ssl_session_timeout 5m;
        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers   on;
    
        location / {
    
            # like above
    
        }
    }
    

    Nginx is so lightweight and fun. Would not hesitate to go with this option.

提交回复
热议问题