Ситуация, когда у вас поднят WebSocket сервер и вы пытаетесь получить к нему доступ, например из Vue.
[bash title=»код»]self.ws = new WebSocket(‘wss://hd.zp.ua:9991’); [/bash]
Вы скорее всего получите ошибку Mixed Content
Mixed Content: The page at ‘https://hd.zp.ua/admin/service’ was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint ‘ws://hd.zp.ua:9991/events’. This request has been blocked; this endpoint must be available over WSS.
[bash title=»код»]use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;
// Iniciando conexão
$server = IoServer::factory(
new HttpServer(
new WsServer(
new SimpleChat()
)
),
9991
);
$server->run();[/bash]
Можно спроксировать запрос к WebSocket серверу через nginx:
[bash title=»код»]location /services/myservice {
# switch off logging
access_log off;
# redirect all HTTP traffic to localhost
proxy_pass http://localhost:9991;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Path rewriting
rewrite /services/myservice/(.*) /$1 break;
proxy_redirect off;
# timeout extension, possibly keep this short if using a ping strategy
proxy_read_timeout 99999s;
}[/bash]
[bash title=»код»]self.ws = new WebSocket(‘wss://hd.zp.ua/services/myservice’);[/bash]
Обратите внимание. Порт 9991 (или тот который вы будете использовать), нельзя открывать наружу.