使用的是 phpstudy 中的 php apache
https-ssl.cof 下
Listen 443
<VirtualHost *:443>
DocumentRoot "xxx\xxx\xxx\xxx"
ServerName 域名
ServerAlias
# Proxy Config
SSLProxyEngine on
ProxyRequests Off
ProxyPass /wss ws://127.0.0.1:8383
ProxyPassReverse /wss ws://127.0.0.1:8383
<Directory "C:\phpStudy\WWW\plane">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP: MEDIUM
SSLEngine on
SSLHonorCipherOrder on
SSLCertificateFile "C:\phpStudy\Apache\cert\public.pem"
SSLCertificateKeyFile "C:\phpStudy\Apache\cert\214952355360180.key"
SSLCertificateChainFile "C:\phpStudy\Apache\cert\chain.pem"
</VirtualHost>
start_gateway.php 下
<?php
// 自動(dòng)加載類
require_once __DIR__ . '/../../vendor/autoload.php';
// gateway 進(jìn)程,這里使用Text協(xié)議,可以用telnet測試
$gateway = new Gateway("websocket://0.0.0.0:8383");
前端請求:
// 證書是會檢查域名的,請使用域名連接
ws = new WebSocket("wss://域名/wss");
ws.onopen = function() {
alert("連接成功");
ws.send('tom');
alert("給服務(wù)端發(fā)送一個(gè)字符串:tom");
};
ws.onmessage = function(e) {
alert("收到服務(wù)端的消息:" e.data);
};