PHP Websocket not working with WSS

i need to use ssl with websocket but still not working, its work only with WS. For WSS i receive ‘TCP connection lost’ error

nginx version 1.2.1

Server started
Listening on: 0.0.0.0:11011
Master socket: Resource id #6
Client connected. Resource id #7
Client disconnected. TCP connection lost: Resource id #7

Nginx config (i have already test upstream but not work)

server {
        listen 80;
        listen   443 ssl;

        root /example.com/www;
        index index.php index.html index.htm;

        server_name example.com;

        location / {
                try_files $uri $uri/ /index.html;
                disable_symlinks off;

        }

        location /ws/ {
            proxy_pass http://127.0.0.1:11011;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_read_timeout 86400;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }

        ssl on;
        ssl_certificate example_com.pem;
        ssl_certificate_key example_com.key;

        ssl_session_timeout 5m;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-$
}

Client javascript

new WebSocket('wss://example.com/ws/');

Php (websocket class link https://github.com/ghedipunk/PHP-Websockets/blob/master/websockets.php)

#!/usr/bin/env php
<?php
require_once('./websockets.php');

class echoServer extends WebSocketServer {
  protected function process ($user, $exec) {
  }

  protected function connected ($user) {
  }

  protected function closed ($user) {
  }
}

$echo = new echoServer("0.0.0.0","11011");

try {
  $echo->run();
}
catch (Exception $e) {
  $echo->stdout($e->getMessage());
}

Why my configuration work only without ssl ? my certificate is correctly installed

Thanks you

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s