在nginx中使用chat.room.com:8020轉(zhuǎn)發(fā)到端口7272的時(shí)候,有些瀏覽器會(huì)出現(xiàn)以下問題,導(dǎo)致無法建立websocket鏈接,錯(cuò)誤提示如下:
** policy file: xmlsocket://chat.room.com:843
cannot connect to Web Socket server at ws://chat.room.com:8020 (SecurityError: Error #2048)
make sure the server is running and Flash socket policy file is correctly placed**
這個(gè)問題應(yīng)該怎么解決?
這個(gè)監(jiān)聽843端口是用nginx來監(jiān)聽還是用workman來做監(jiān)聽?
這個(gè)policy file是不是下面這個(gè)?
crossdomain.xml
<?xml version="1.0" ?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="_" to-ports="_" secure="false"/>
<allow-http-request-headers-from domain="_" headers="_"/>
</cross-domain-policy>
用workerman提供即可,就下面幾行代碼
<?php
use Workerman\Worker;
require_once __DIR__ . '/Workerman/Autoloader.php';
$flash_policy = new Worker('tcp://0.0.0.0:843');
$flash_policy->onMessage = function($connection, $message)
{
$connection->send('<?xml version="1.0"?><cross-domain-policy><site-control permitted-cross-domain-policies="all"/><allow-access-from domain="_" to-ports="_"/></cross-domain-policy>'."\0");
};
if(!defined('GLOBAL_START'))
{
Worker::runAll();
}
還是出現(xiàn)獲取不到的錯(cuò)誤,錯(cuò)誤如下圖
[attach]218[/attach]
[attach]219[/attach]
[attach]220[/attach]