Search code examples
apachesslwebsocketautobahnthruway

How to use secure websockets (wss)?


I'm using AutobahnJS and Thruway on my website and everything works fine using a nonencrypted connection:

var connection = new autobahn.Connection({
                                             url: 'ws://www.example.com:9090',
                                             realm: 'restricted_realm'
                                         });

connection.onopen = function (session) {
    alert('yay');
};

connection.open();

However, I am unable to use a secure connection. Changing ws://www.mysite.com:9090 to wss://www.example.com:9090 results in this error in the console:

WebSocket connection to 'wss://www.example.com:9090/' failed: Error in connection establishment: net::ERR_TIMED_OUT

I have an SSL certificate on my server and can access my site via https://www.example.com.

What do I need to do to make secure websockets work?


Solution

  • Thruway uses Ratchet as the underlying transport for WebSockets, so you can reference their documentation on deploying:

    http://socketo.me/docs/deploy

    You can also use stunnel or nginx.