Hello. Translated the site to https and can not figure out how to translate sockets. On http, sockets were connected via ws://sitename.com:3003 , now they need to be accessible via wss://sitename.com:3003 . Tell me, please, how to do it.

PHP:

 $loop = React\EventLoop\Factory::create(); $context = new React\ZMQ\Context($loop); $pull = $context->getSocket(ZMQ::SOCKET_PULL); $pull->bind('tcp://127.0.0.1:3004'); $pull->on('message', array($pusher, 'onMessage')); $webSock = new React\Socket\Server($loop); $webSock->listen(3003, '0.0.0.0'); $webServer = new Ratchet\Server\IoServer( new Ratchet\Http\HttpServer( new Ratchet\WebSocket\WsServer( new Ratchet\Wamp\WampServer( $pusher ) ) ), $webSock ); $loop->run(); 

Js:

 window.phpSocket = new ab.Session('wss://sitename.com:3003', 

Nginx:

 server { listen 443 ssl; keepalive_timeout 70; client_max_body_size 500M; root /var/www/path/to/site/root; index index.php; server_name sitename.com; gzip_static on; gzip on; gzip_min_length 1000; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain application/xml text/css text/javascript application/javascript; ssl on; ssl_certificate /etc/letsencrypt/live/sitename.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/sitename.com/privkey.pem; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; 

    2 answers 2

    before server {

     upstream websocket { server ВАШ_ДОМЕН:3003; } 

    inside server {

     location / { proxy_pass http://ВАШ_ДОМЕН; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_read_timeout 3600; } 
    • I tried, it does not work. Just do not go connection. - Igor
    • I did not notice that you are using Ratchet. Try the edited config above. - tcpack4
    • Tried it like this - it gave the error "WebSocket handshake: Unexpected response code: 301". - Igor
    • without debug at the protocol level, I can’t say anything. Maybe someone else will tell. And so the advice is to debug using tcpdump for example. See if the server has started and whether the specified protocol is listening. It can send requests directly through curl (or some convenient tool), given that the protocol is simple (the wiki article explains well). - tcpack4

    The problem was solved independently! Learn more: https://toster.ru/answer?answer_id=1071432#answers_list_answer