I use Moodle 3.5.11 on FreeBSD with Letsencypt HTTPS.
In moodle source code "http" is hardcoded, so requests to chat demon sended by http and browser blocks this requests.
I install stunnel and make some changes in moodle source code to redirect to https instead on http
pkg install stunnel
cp /usr/local/etc/stunnel/stunnel.conf-sample /usr/local/etc/stunnel/stunnel.conf
mkdir /var/run/stunnel
touch /var/run/stunnel/stunnel.pid
chown -R stunnel:nogroup /var/run/stunnel
touch /var/log/stunnel.log
chown stunnel:nogroup /var/log/stunnel.log
sysrc stunnel_enable=yes
/usr/local/etc/stunnel/stunnel.conf
+ setuid = stunnel
+ setgid = nogroup
+ output = /var/log/stunnel.log
+ [moodle-php-chat]
+ cert = /usr/local/etc/letsencrypt/live/DOMAIN/fullchain.pem
+ key = /usr/local/etc/letsencrypt/live/DOMAIN/privkey.pem
+ socket = l:TCP_NODELAY=1
+ socket = r:TCP_NODELAY=1
+ accept = MYEXTERNALIP:9111
+ connect = 127.0.0.1:9112
/usr/local/etc/stunnel/conf.d/00-pid.conf
- pid = /var/tmp/run/stunnel.pid
+ pid = /var/run/stunnel/stunnel.pid
/usr/hosting/u1/www/edu/html/mod/chat/chatd.php
+ $CFG->chat_serverport = 9112;
- $_SERVER['PHP_SELF'] = "http://$CFG->chat_serverhost:$CFG->chat_serverport/mod/chat/chatd.php";
+ $_SERVER['PHP_SELF'] = "https://$CFG->chat_serverhost:$CFG->chat_serverport/mod/chat/chatd.php";
/usr/hosting/u1/www/edu/html/mod/chat/gui_sockets/chatinput.php
- <form action="<?php echo "http://$CFG->chat_serverhost:$CFG->chat_serverport/"; ?>" method="get" target="empty" id="sendform">
+ <form action="<?php echo "https://$CFG->chat_serverhost:$CFG->chat_serverport/"; ?>" method="get" target="empty" id="sendform">
/usr/hosting/u1/www/edu/html/mod/chat/gui_sockets/index.php
- $winchaturl = "http://$CFG->chat_serverhost:$CFG->chat_serverport?win=chat&$params";
- $winusersurl = "http://$CFG->chat_serverhost:$CFG->chat_serverport?win=users&$params"
+ $winchaturl = "https://$CFG->chat_serverhost:$CFG->chat_serverport?win=chat&$params";
+ $winusersurl = "https://$CFG->chat_serverhost:$CFG->chat_serverport?win=users&$params"