就是ws的时候还是可以的 使用https之后 网站可以访问 但是wss的连接一直报错 按照百度的提示更改nginx也不起作用 报错:
WebSocket connection to 'wss://codepalace.xyz:2346/wss' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
nginx配置:
server {
listen 443;
server_name www.codepalace.xyz;
ssl on;
ssl_certificate 1_www.codepalace.xyz_bundle.crt;
ssl_certificate_key 2_www.codepalace.xyz.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
root /var/www/html/blog/public;
index index.php;
location /wss{
proxy_pass http://127.0.0.1:2346;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
rewrite /wss/(.*) /$1 break;
proxy_redirect off;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# pass PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
}
js:
let protocol = location.protocol === 'https:'
? 'wss://codepalace.xyz:2346/wss'
: 'ws://0.0.0.0:2346';
ws = new WebSocket(protocol);php: private function startGateWay(){
$gateway = new Gateway("websocket://127.0.0.1:2346");
$gateway->name = 'Gateway';
$gateway->count =1;
$gateway->lanIp = '127.0.0.1';
$gateway->startPort=2300;
$gateway->pingInterval=30;
$gateway->pingNotResponseLimit=0;
$gateway->pingData= '{"type":"heart"}';
$gateway->registerAddress="127.0.0.1:1236";
}
解决了 js里面不需要再写端口号了☺️ 我的天
是的,手册示例里这样nginx代理443不用加端口号的