第一步:把依赖填写一下:
"workerman/gatewayclient": "^3.0", "workerman/workerman": "^4.1", "workerman/gateway-worker": "^3.1"
【第二步】Composer安装
如果没有安装过 composer 的,先执行安装: composer install 。如果安装过,不需要安装,直接执行下面的依赖。
composer require workerman/workerman
【第三步】开启端口 8282 和 1236 这两个端口
【第四步】启动 即时通信长链接
start.php 文件放在网站的根目录
php start.php start -d
成功显示
【第五步】填写伪静态
location ~* \.(eot|ttf|woff|svg|otf|woff2)$ { add_header Access-Control-Allow-Origin *; } location / { # 这里配置单个代理跨域,跨域配置 add_header 'Access-Control-Allow-Origin' *; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' *; add_header 'Access-Control-Allow-Headers' *; # *指允许所有,也可指定,例如:http://10.0.0.56 add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS; if (-f $request_filename) { break; } if ($request_filename ~* "\.(js|ico|gif|jpe?g|bmp|png|css)$") { break; } if (!-e $request_filename) { rewrite . /index.php last; } } location /m/ { if (-f $request_filename) { break; } if ($request_filename ~* "\.(js|ico|gif|jpe?g|bmp|png|css)$") { break; } if (!-e $request_filename) { rewrite . /m/index.html last; } } location /wss { proxy_pass http://duixin.cc:8282; 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; }
注意:在伪静态里面的网址修改为你的网址。
proxy_pass http://duixin.cc:8282;
【第六步】在小程序里面填写 wss 网址
位置在:开发》》开发管理》》开发设置 》》 socket合法域名