Been researching the issue with Ratchet over SSL and have been trying to get my Apache2 server configuration working by enabling proxy.load and proxy\_wstunnel.load mods. 

```
/etc/apache2/mods-enabled:
     proxy.conf -> ../mods-available/proxy.conf
     proxy.load -> ../mods-available/proxy.load
     proxy_wstunnel.load -> ../mods-available/proxy_wstunnel.load

```

I've added the following line to the end of my apache2.conf: 

`ProxyPass /wss2/ ws://domain.com:8080`

The PHP socket-server.php file:

```
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Websocket\SocketControl;
use Ratchet\Session\SessionProvider;
use Symfony\Component\HttpFoundation\Session\Storage\Handler;

    require dirname(__DIR__) . '/vendor/autoload.php';

    $memcache = new Memcache;
    $memcache->connect('localhost', 11211);

    $session = new SessionProvider(
        new SocketControl,
        new Handler\MemcacheSessionHandler($memcache)
    );

    $server = IoServer::factory(
        new HttpServer(
            new WsServer(
                $session
            )
        ),
        8080
    );

    $server->run();

```

The relevant JS code that attempts to connect to the socket server:

```
var websocket = {
    wsUri:"wss://domain.com/wss2/NNN",
    socket:null,
    cryptKey:null,
    init:function(){
        try {
            if (typeof MozWebSocket == "function")
                WebSocket = MozWebSocket;
            if ( websocket.socket && websocket.socket.readyState == 1 )
                websocket.socket.close();

            websocket.socket = new WebSocket( websocket.wsUri );
            websocket.socket.onopen = websocket.onopen.bind();
            websocket.socket.onclose = websocket.onclose.bind();
            websocket.socket.onmessage = websocket.onmessage.bind();
            websocket.socket.onerror = websocket.onerror.bind();

        } catch (exception) {
            console.log("ERROR: " + exception);
        }
    },

```

The error I receive when attempting to connect:

`WebSocket connection to 'wss://domain.com/wss2/NNN' failed: Error during WebSocket handshake: Unexpected response code: 502`