Answer the question
In order to leave comments, you need to log in
Websockets on https?
Good time!
Tell me how to set up websockets on https
I read this article , made a chat, everything worked, then I had to transfer the chat to a site with https, moved it and made some changes, found some on the network, but it doesn’t work at the stage where you need to read from the connection, and I can't find what to do
$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'local_cert', "/etc/letsencrypt/live/папка/cert.pem");
stream_context_set_option($context, 'ssl', 'local_pk', "/etc/letsencrypt/live/папка/privkey.pem");
stream_context_set_option($context, 'ssl', 'ciphers', 'ALL');
stream_context_set_option($context, 'ssl', 'verify_peer', false);
stream_context_set_option($context, 'ssl', 'verify_peer_name', false);
$socket = stream_socket_server("ssl://".$ipsocket, $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
while (true) {
$read = $connects;
$read[] = $socket;
$write = $except = null;
if (!stream_select($read, $write, $except, null)) {break;}
if (in_array($socket, $read)) {//есть новое соединение
//принимаем новое соединение и производим рукопожатие:
if (($connect = stream_socket_accept($socket, -1)) && $info = handshake($connect)) {
тут пропущено
function handshake($connect) {
$line = fread($connect, 1500);
Answer the question
In order to leave comments, you need to log in
Accept https on nginx and proxy to the one who has your chat there. Your hair will be clean and silky.
Look for "how to set up a reverse proxy" both Apache and nginx have such an opportunity and it will decrypt traffic and send it to you via http itself at first I wanted to implement https support in my project I suffered for more than a month (the project was in C ++) spat and now Years with reverse proxy do not know grief.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question