简体   繁体   中英

PHP Websocket ERROR: net::ERR_SSL_PROTOCOL_ERROR using cloudflare

By now, I had working PHP Ratchet Websocket over SSL. Lately, I've set up cloudflare in my website. After doing so, I get an error in client side: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR . As I check, The websocket server, in the backend, is indeed working and waiting for connections to be established.

Here is the fornt-end websocket establishment: const conn = new WebSocket('wss://xyz:8080');

And here is my websocket server set up:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use dealspace_websocket\Chat;

$app = new HttpServer(
    new WsServer(
        new Chat()
    )
);

$loop = \React\EventLoop\Factory::create();

$privateKEY = __DIR__ . '/../private/private.pem';
$publicKEY = __DIR__ . '/../private/public.pem';
$secure_websockets = new \React\Socket\Server('0.0.0.0:8080', $loop);
$secure_websockets = new \React\Socket\SecureServer($secure_websockets, $loop, [
    'local_cert' => $publicKEY,
    'local_pk' => $privateKEY,
    'verify_peer' => false
]);

$secure_websockets_server = new \Ratchet\Server\IoServer($app, $secure_websockets, $loop);
$secure_websockets_server->run();

?>

I've also enabled errors in the server, but I don't get any when running the server.

If your server use a proxy with Cloudflare, the secure Websocket can only use a HTTPS port supported by Cloudflare: https://support.cloudflare.com/hc/en-us/articles/200169156-Which-ports-will-Cloudflare-work-with-

  • 443
  • 2053
  • 2083
  • 2087
  • 2096
  • 8443

If traffic for your domain is destined for a different port than listed above, either: Add the subdomain as a gray-clouded record via your Cloudflare DNS app, or Enable Cloudflare Spectrum.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM