您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman創建wss服務(基於apache基於phpstudy環境)
发布时间:2022-01-09 13:03:30编辑:雪饮阅读()
上篇配置了基於nginx基於寶塔環境下wss服務。
那麽這次的php服務端脚本保持不變,JavaScript客戶端代碼修改下
<!doctype html>
<html>
<head>
<script>
ws2 = new WebSocket("wss://www.apache.com/wss");
ws2.onopen=function(evt){
console.log("ws2 connect success!",evt);
var order={
order_id:220807,
uid:2022
}
ws2.send(JSON.stringify(order));
};
ws2.onmessage = function(e) {
console.log("ws2 receive message:" + e.data);
};
</script>
</head>
<body>
<div class="container">
</div>
</body>
</html>
<html>
<head>
<script>
ws2 = new WebSocket("wss://www.apache.com/wss");
ws2.onopen=function(evt){
console.log("ws2 connect success!",evt);
var order={
order_id:220807,
uid:2022
}
ws2.send(JSON.stringify(order));
};
ws2.onmessage = function(e) {
console.log("ws2 receive message:" + e.data);
};
</script>
</head>
<body>
<div class="container">
</div>
</body>
</html>
我在phpstudy中同默認的localhost站點綁定的。
那麽這裏ssl對於phpstudy來説開啓很簡單
在該站點上開啓https
這裏的東西都可以直接使用“生成開發者測試證書”
然後需要檢查httpd.conf(D:\phpstudy_pro\Extensions\Apache2.4.39\conf\httpd.conf)中的兩個配置
LoadModule proxy_module modules/mod_proxy.so
和
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so是否被注釋,若注釋了就去除前面的#注釋。
然後配置0localhost_443.conf(這裏的前導0可能會變,我這裏只有一個站點應該默認是第一個站點前導為0吧,路徑如:D:\phpstudy_pro\Extensions\Apache2.4.39\conf\vhosts\0localhost_443.conf):
<VirtualHost _default_:443>
DocumentRoot "D:/phpstudy_pro/WWW/xuexibiji"
SSLEngine on
SSLCertificateFile "D:/phpstudy_pro/Extensions/Apache2.4.39/conf/ssl/localhost.crt"
SSLCertificateKeyFile "D:/phpstudy_pro/Extensions/Apache2.4.39/conf/ssl/localhost.key"
FcgidInitialEnv PHPRC "D:/phpstudy_pro/Extensions/php/php7.1.9nts"
AddHandler fcgid-script .php
FcgidWrapper "D:/phpstudy_pro/Extensions/php/php7.1.9nts/php-cgi.exe" .php
ErrorLog "D:/phpstudy_pro/Extensions/Apache2.4.39/logs/localhost_error.log"
SSLProxyEngine on
ProxyRequests Off
ProxyPass /wss ws://192.168.43.170:8282/wss
ProxyPassReverse /wss ws://192.168.43.170:8282/wss
<Directory "D:/phpstudy_pro/WWW/xuexibiji">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
DirectoryIndex index.html index.php
</Directory>
</VirtualHost>
紅色部分為我添加的配置,其中192.168.43.170就是上篇中那個php寫的websocket服務端所在linux服務器地址,那麽8282也正是其監聽的端口。
然後回到phpstudy首頁重啓下wamp組合即可
然後https和wss服務就都ok了
关键字词:workerman,wss,apache,phpstudy