Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP websockets没有';t在wss上工作://_Php_Ssl_Nginx_Websocket_Ratchet - Fatal编程技术网

PHP websockets没有';t在wss上工作://

PHP websockets没有';t在wss上工作://,php,ssl,nginx,websocket,ratchet,Php,Ssl,Nginx,Websocket,Ratchet,我将我的站点移动到https://。 在http到sockets的连接中,有一个通过ws://sitename.com:3003的连接,现在有必要在wss://sitename.com:3003上提供这些连接。 我该怎么做? 多谢各位 PHP: JS: nginx: server { listen 443 ssl; keepalive_timeout 70; client_max_body_size 500M; root /var/www/path

我将我的站点移动到https://。 在http到sockets的连接中,有一个通过ws://sitename.com:3003的连接,现在有必要在wss://sitename.com:3003上提供这些连接。 我该怎么做? 多谢各位

PHP:

JS:

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;

因为nginx conf没有指定如何将客户端wss转发到3003侦听的服务器端口

您应该将其添加到nginx.conf中的服务器块中

location /wss/ {
    proxy_pass http://localhost:3003;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
并将您的Js代码更改为:

window.phpSocket = new ab.Session('wss://sitename.com/wss/',
有关如何将nginx用作websocket\u代理的更多信息,请参阅

location /wss/ {
    proxy_pass http://localhost:3003;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
window.phpSocket = new ab.Session('wss://sitename.com/wss/',