workerman
workerman copied to clipboard
Cloudflare universal ssl
How to work with cloudflare edge certificates? I can't run socket about of several days, because workerman requires certificate file but i can't catch it, because can't obtain certificate code and private key. How can i work with cloudflare universall ssl?
Hi @Raserad,
If I understand correctly you want to run workerman with ssl/tls ?
First you will need a ssl certificate. Wich you can get from cloudfare or elsewhere. Your certificate should include a certificate file and a key file.
Then you can run workerman like this:
<?php
use Workerman\Worker;
require_once __DIR__ . '/vendor/autoload.php';
$context = [
'ssl' => [
'local_cert' => '/path/to/your/certificate/file', // Probably something like: certificate.pem
'local_pk' => '/path/to/your/key/file', // Probably something like: certificate.key
]
];
// Create your websocket or http socket.
$worker = new Worker('websocket://0.0.0.0:8080', $context);
// Set the transport to ssl
$worker->transport = 'ssl';
// Then you can run workerman like any other time.
Worker::runAll();
I would recomend you to run workerman behind a proxy (nginx for example) for ssl/tls ofloading, it will be far easier and will probably offer higger security. You can find plenty of guides online on how to setup a nginx proxy.