phpsocket.io icon indicating copy to clipboard operation
phpsocket.io copied to clipboard

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

Open wbsartori opened this issue 2 years ago • 3 comments

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
    ]
];

wbsartori avatar Dec 05 '23 21:12 wbsartori

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

walkor avatar Dec 06 '23 08:12 walkor

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

wbsartori avatar Dec 06 '23 12:12 wbsartori

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.

AbdullahFaqeir avatar Mar 28 '24 16:03 AbdullahFaqeir