thinkphp-swoole运行报错和wss无法访问的问题
thinkphp6.0
项目,在运行swoole
服务时log日志疯狂报错
$ php think swoole restart
整了好几个小时结果是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://
andwss://
- 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 notwss://
) and that you expect the TLS from the HTTP server (port 443) to be magically applied towss://
on port 8090 too. This is not the case. By tryingwss://
with port 8090 you are instead trying to do a TLS handshake with a server which does not speak TLS, which then results innet::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://
andwss://
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)
引用
1.WebSocket error: net::ERR_SSL_PROTOCOL_ERROR: https://stackoverflow.com/questions/59542929/websocket-error-neterr-ssl-protocol-error
评论 (0)