调用博主最近登录时间
生活中的HYGGE
thinkphp-swoole运行报错和wss无法访问的问题
PHP

thinkphp-swoole运行报错和wss无法访问的问题

hygge
2024-08-09 / 0 评论 / 91 阅读 / 正在检测是否收录...

thinkphp-swoole运行报错和wss无法访问的问题

thinkphp6.0项目,在运行swoole服务时log日志疯狂报错

$ php think swoole restart

lzlz1zhk.png

整了好几个小时结果是php版本问题,当时默认切到了php8...

更换命令为73就好了

$ /www/server/php/73/bin/php think swoole restart

运行起来后ws:协议正常访问,wss无法访问

问题如下:

You are trying to use the same port (8090) for ws:// and wss:// - this will most likely not work. While you don't show any server side configuration I suspect that your websocket server on port 8090 can only do plain WebSockets (i.e. ws:// and not wss://) and that you expect the TLS from the HTTP server (port 443) to be magically applied to wss:// on port 8090 too. This is not the case. By trying wss:// with port 8090 you are instead trying to do a TLS handshake with a server which does not speak TLS, which then results in net::ERR_SSL_PROTOCOL_ERROR.

The common setup is instead to use a web server like nginx or Apache as reverse proxy for the websocket server and terminate the TLS at the web server. This way both ws:// and wss:// work on the standard ports (i.e. 80 and 443) from outside and the internet plain websocket server on port 8090 is will be made unreachable from outside. See for example NGINX to reverse proxy websockets AND enable SSL (wss://)? or WebSocket through SSL with Apache reverse proxy for how to setup something like this.

需要为项目配置一个反向代理

    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewritexxxx.conf;
    #REWRITE-END
  
    location /app {
        proxy_pass http://127.0.0.1:9999;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
        proxy_request_buffering off;
    }

    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)

lzlz297w.png

引用

1.WebSocket error: net::ERR_SSL_PROTOCOL_ERROR: https://stackoverflow.com/questions/59542929/websocket-error-neterr-ssl-protocol-error

0

评论 (0)

取消