php ratchet websocket SSL connect?

后端 未结 9 2077
遥遥无期
遥遥无期 2020-11-27 03:30

I have a ratchet chat server file

use Ratchet\\Server\\IoServer;
use Ratchet\\WebSocket\\WsServer;
use MyAppChat\\Chat;
require dirname(__DIR__) . \'/vendor/         


        
相关标签:
9条回答
  • 2020-11-27 03:52

    Apache also worked for me, just add in domain conf:

    ProxyPass /wss/ wss://127.0.0.1:8888/
    

    Reload apache and then it's import to set wss in client side to include /wss/ location

    wss://127.0.0.1/wss/
    
    0 讨论(0)
  • 2020-11-27 03:57

    A few days ago I was looking for the answer of this question and I found this in the Github Ratchet issues: https://github.com/ratchetphp/Ratchet/issues/489

    The last answer, answered by heidji, says this:

    I only added this comment for newbies like me who need a quick instruction how to implement SSL: Via the ReactPHP docs you only need to construct the SecureServer mentioned in such manner:
    $webSock = new React\Socket\Server('0.0.0.0:8443', $loop);
    $webSock = new React\Socket\SecureServer($webSock, $loop, ['local_cert' => '/etc/ssl/key.pem', 'allow_self_signed' => true, 'verify_peer' => false]);
    and then inject into the IoServer as mentioned by cboden above

    So it seems that now there is a way to implement a secure websocket server with Ratchet without needing an HTTPS proxy.

    Here you have the SecureServer class documentation: https://github.com/reactphp/socket#secureserver

    0 讨论(0)
  • 2020-11-27 04:01

    If you are using Windows IIS, make sure that you have configured it for HTTPS (I'm using self signed certificate), then install reverse proxy:

    URL rewrite: https://www.iis.net/downloads/microsoft/url-rewrite and ARR 3.0: https://www.iis.net/downloads/microsoft/application-request-routing

    You also need to enable websockets support in IIS:

    create folder (e.g. myproxyfolder) for URL rewrite, on this folder create web.config file with content:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="WebSocketProxy" stopProcessing="true">
                        <match url="(.*)" />
                        <action type="Rewrite" url="http://127.0.0.1:8080" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    and change "http://127.0.0.1:8080" to your websocket service (I'm using Ratched for PHP on WIN).

    On client side in javascript, use secure websockets wss:// protocol, like:

        mysock = new WebSocket('wss://127.0.0.1/myproxyfolder');
    ...
    
    0 讨论(0)
提交回复
热议问题