walkor / phpsocket.io

A server side alternative implementation of socket.io in PHP based on workerman.
2.3k stars 508 forks source link

How can I use PHP Socket.IO with Nginx/SSL or without SSL? #301

Open wbsartori opened 10 months ago

wbsartori commented 10 months ago

Currently I use the socket passing the port and default settings of the SSL certificate. I would like to be able to use SSL directly with nginx so that it can manage the certificate for me. I found other issues talking about usage, but I wasn't successful in any of them.

My instance runs around this call:

    $io = new SocketIO($port, $sslContext);

My SSL configuration is in this format:

$sslContext = [
    'ssl' => [
       'local_cert' => '/etc/nginx/ssl/nginx.crt',
       'local_pk' => '/etc/nginx/ssl/nginx.key',
       'allow_self_signed' => true,
       'verify_peer' => false
    ]
];
walkor commented 10 months ago

This is an example for nginx config

server {

  location /socket.io
  {
    proxy_pass http://127.0.0.1:2120;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Real-IP $remote_addr;
  }

}

Remember remove ssl config from phpsocket.io

wbsartori commented 10 months ago

Does this usage format also work if I am using supervisor for my websocket service? Or would I need to do some additional configuration?

AbdullahFaqeir commented 6 months ago

Does this usage format also work if I am using supervisor for my websocket service? Or would I need to do some additional configuration?

If you want to use it with nginx/apache for SSL, it's pretty simple just like the above comment stated, nginx/apache will be handling the networking and SSL, it's called reverse proxy, and yes it can work with supervisor or forever.