php ratchet websocket SSL connect?

后端 未结 9 2222
遥遥无期
遥遥无期 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:47

    If you're using Nginx, just write this in your SSL server block:

    location /services/myservice {
        # switch off logging
        access_log off;
    
        # redirect all HTTP traffic to localhost
        proxy_pass http://localhost:1234;
        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;
    }
    

    This will upgrade any wss://yoursite.com/services/myservice call to a socket running on port 1234. Just make sure you remember not to leave port 1234 open to the world.

提交回复
热议问题