我有一个用php写的WebSocket服务器,它是棘轮websocket服务器。我为apache启用了wstunnel。我还在我的网站配置中添加了ProxyPass
这是我的网站的Apache配置。
<VirtualHost *:443>
DocumentRoot /var/www/mywebsite/pav/
ServerName www.mywebsite.com
ServerAlias mywebsite.com
RewriteEngine on
ProxyPass /wss2/ ws://www.mywebsite.com:8080
<Directory /var/www/mywebsite/pav/>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
字符串
我的网站是用PHP和JS写的。在JavaScript中,我用来连接服务器的脚本是
var socket = new WebSocket('wss://www.mywebsite.com:8080');
型
我在我的浏览器(Firefox)中使用inspect检查,并在控制台中显示:Firefoxwww.xpatvoice.com:8080/。
我尝试了其他浏览器,得到了同样的结果。
问题是我不知道如何判断是什么导致它失败,我的意思是任何错误代码或错误日志来诊断问题。
我也试过
var socket = new WebSocket('wss://www.mywebsite.com/wss2/:8080');
型
下面是聊天套接字类
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Socket implements MessageComponentInterface {
public function __construct()
{
$this->clients = new \SplObjectStorage;
$this->users = [];
$this->inqs = [];
}
public function onOpen(ConnectionInterface $conn) {
// Store the new connection in $this->clients
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
//echo $conn->httpRequest->headers["X-Forwarded-For"][0];
}
public function onMessage(ConnectionInterface $from, $msg) {
$data = json_decode($msg);
$userinfo = json_decode($data->userinfo,true);
if(isset($userinfo["userId"]) && $data->action == "userLogin"){
$userID = $userinfo["userId"];
$this->users[$userID]["conn"] = $from;
$this->users[$userID]["role"] = $userinfo["role"];
echo "attached user $userID\n";
// NOTIFY INQUISITORS OF ADMIN LOGIN
if($userinfo["role"] < 3){
foreach($this->inqs as $inq => $client){
$message["action"] = "adminLogon";
$client->send(json_encode($message));
}
}
}
if(isset($userinfo["userId"]) && $data->action == "adminReply"){
$this->inqs[$data->to]->send($msg);
}
if(isset($userinfo["tempuser"]) && $data->action == "enquiry"){
$userID = $userinfo["tempuser"];
$this->inqs[$userID] = $from;
echo "attached inquisitor $userID\n";
}
if(isset($userinfo["tempuser"])){
foreach($this->users as $userid => $user){
if($user["role"] < 3){
$user["conn"]->send($msg);
}
}
echo "message from inquisitor\n";
}
}
public function onClose(ConnectionInterface $conn) {
$this->clients->detach($conn);
}
public function onError(ConnectionInterface $conn, \Exception $e) {
}
}
型
我启用了proxy,proxy_wstunnel,proxy_http
sudo a2enmod proxy
output: Module proxy already enabled
sudo a2enmod proxy_wstunnel
output: Module proxy_wstunnel already enabled
sudo a2enmod proxy_http
output: Module proxy_http already enabled
型
使用Apache/2.4.41
1条答案
按热度按时间u0sqgete1#
所以我遵循hakre的建议,查看了位于/var/log/apache 2/error. log中的php/apache错误日志,每当我试图从浏览器连接到socket服务器时,就会出现这个错误。
第一个月
我在谷歌上搜索了一下,在这里的这个链接中找到了我的答案
https://unix.stackexchange.com/questions/240590/why-is-apache-giving-dns-lookup-failures
事实证明,这个错误是在我的网站的Apache配置中。