Loading... # ChatGPT-Pro部署文档 适用版本:v1.3.0以上 前端开源地址:[gitee.com/shoujing100…](https://link.juejin.cn?target=https%3A%2F%2Fgitee.com%2Fshoujing1001%2Fchatgpt-uniapp "https://gitee.com/shoujing1001/chatgpt-uniapp") 管理端开源地址:[gitee.com/shoujing100…](https://link.juejin.cn?target=https%3A%2F%2Fgitee.com%2Fshoujing1001%2Fchatgpt-admin "https://gitee.com/shoujing1001/chatgpt-admin") uni-app插件市场:[ext.dcloud.net.cn/plugin?id=1…](https://link.juejin.cn?target=https%3A%2F%2Fext.dcloud.net.cn%2Fplugin%3Fid%3D11833 "https://ext.dcloud.net.cn/plugin?id=11833") ## 系统架构介绍 ### 服务端 * PHP >=7.4 <8 * webman 1.4 * Redis 7.0 ### 后台管理端 * vue-cli2 * element-ui2 ### 客户端 * uni-app 适用小程序、公众号、普通H5、APP、PC ## 部署服务端及管理后台 ### 环境检查 * `php -v`检查php版本需为7.4以上 * 确保以下函数解除禁用 <pre><div class="code-block-extension-header"><div class="code-block-extension-headerLeft"><div class="code-block-extension-foldBtn"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M16.924 9.617A1 1 0 0 0 16 9H8a1 1 0 0 0-.707 1.707l4 4a1 1 0 0 0 1.414 0l4-4a1 1 0 0 0 .217-1.09z" data-name="Down"></path></svg></div></div><div class="code-block-extension-headerRight"><span class="code-block-extension-lang">bash</span><div class="code-block-extension-copyCodeBtn">复制代码</div></div></div><code class="hljs language-bash code-block-extension-codeShowNum" lang="bash"><span class="code-block-extension-codeLine" data-line-num="1">shell_exec</span> <span class="code-block-extension-codeLine" data-line-num="2">pcntl_signal</span> <span class="code-block-extension-codeLine" data-line-num="3">pcntl_fork</span> <span class="code-block-extension-codeLine" data-line-num="4">pcntl_wait</span> <span class="code-block-extension-codeLine" data-line-num="5">pcntl_signal_dispatch</span> <span class="code-block-extension-codeLine" data-line-num="6">pcntl_alarm</span> <span class="code-block-extension-codeLine" data-line-num="7">exec</span> </code></pre> * 确保php-cli开启了redis扩展,使用以下命令检查: <pre><div class="code-block-extension-header"><div class="code-block-extension-headerLeft"><div class="code-block-extension-foldBtn"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M16.924 9.617A1 1 0 0 0 16 9H8a1 1 0 0 0-.707 1.707l4 4a1 1 0 0 0 1.414 0l4-4a1 1 0 0 0 .217-1.09z" data-name="Down"></path></svg></div></div><div class="code-block-extension-headerRight"><span class="code-block-extension-lang">perl</span><div class="code-block-extension-copyCodeBtn">复制代码</div></div></div><code class="hljs language-perl code-block-extension-codeShowNum" lang="perl"><span class="code-block-extension-codeLine" data-line-num="1">php -m | grep redis</span> </code></pre> 有多个php版本的,注意只能一个php版本的redis扩展。 如之前安装有其他redis版本,请卸载其他redis版本,将php7.4的redis版本安装后,切换命令行php版本一次或重启服务器,需要保证 ` php -m | grep redis`有结果。 如果没有,使用 `php --ini`检查配置文件路径是否正确。 ### 宝塔面板新建网站 ### 将代码上传到网站根目录 ### 选定网站目录为/public ### 为网站配置ssl证书 注意:服务器IP在海外且未配置ssl证书或者国内未开启强制https可能导致微信jsapi支付回调不能正常通知。 ### 导入数据库 ### 修改数据库配置文件 修改 `config\database.php`文件,改为你自己的数据库及密码 ### 写入授权码文件 修改 `resource\secauth`文件内容为获取的授权码。 ### 设置nginx配置文件 <pre><div class="code-block-extension-header"><div class="code-block-extension-headerLeft"><div class="code-block-extension-foldBtn"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M16.924 9.617A1 1 0 0 0 16 9H8a1 1 0 0 0-.707 1.707l4 4a1 1 0 0 0 1.414 0l4-4a1 1 0 0 0 .217-1.09z" data-name="Down"></path></svg></div></div><div class="code-block-extension-headerRight"><span class="code-block-extension-lang">ruby</span><div class="code-block-extension-copyCodeBtn">复制代码</div></div></div><code class="hljs language-ruby code-block-extension-codeShowNum" lang="ruby"><span class="code-block-extension-codeLine" data-line-num="1"># 开始</span> <span class="code-block-extension-codeLine" data-line-num="2">upstream chat_ai {</span> <span class="code-block-extension-codeLine" data-line-num="3"> server 127.0.0.1:8998;</span> <span class="code-block-extension-codeLine" data-line-num="4"> keepalive 10240;</span> <span class="code-block-extension-codeLine" data-line-num="5">}</span> <span class="code-block-extension-codeLine" data-line-num="6"># 结束</span> <span class="code-block-extension-codeLine" data-line-num="7">server</span> <span class="code-block-extension-codeLine" data-line-num="8">{</span> <span class="code-block-extension-codeLine" data-line-num="9"> listen 80;</span> <span class="code-block-extension-codeLine" data-line-num="10"> listen 443 ssl http2;</span> <span class="code-block-extension-codeLine" data-line-num="11"> server_name domain.com;</span> <span class="code-block-extension-codeLine" data-line-num="12"> index index.php index.html index.htm default.php default.htm default.html;</span> <span class="code-block-extension-codeLine" data-line-num="13"> root /www/wwwroot/chat-ai-server/public;</span> <span class="code-block-extension-codeLine" data-line-num="14"></span> <span class="code-block-extension-codeLine" data-line-num="15"> #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则</span> <span class="code-block-extension-codeLine" data-line-num="16"> #error_page 404/404.html;</span> <span class="code-block-extension-codeLine" data-line-num="17"> #HTTP_TO_HTTPS_START</span> <span class="code-block-extension-codeLine" data-line-num="18"> if ($server_port !~ 443){</span> <span class="code-block-extension-codeLine" data-line-num="19"> rewrite ^(/.*)$ https://$host$1 permanent;</span> <span class="code-block-extension-codeLine" data-line-num="20"> }</span> <span class="code-block-extension-codeLine" data-line-num="21"> #HTTP_TO_HTTPS_END</span> <span class="code-block-extension-codeLine" data-line-num="22"> ssl_certificate /www/server/panel/vhost/cert/domain.com/fullchain.pem;</span> <span class="code-block-extension-codeLine" data-line-num="23"> ssl_certificate_key /www/server/panel/vhost/cert/domain.com/privkey.pem;</span> <span class="code-block-extension-codeLine" data-line-num="24"> ssl_protocols TLSv1.1 TLSv1.2;</span> <span class="code-block-extension-codeLine" data-line-num="25"> ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;</span> <span class="code-block-extension-codeLine" data-line-num="26"> ssl_prefer_server_ciphers on;</span> <span class="code-block-extension-codeLine" data-line-num="27"> ssl_session_cache shared:SSL:10m;</span> <span class="code-block-extension-codeLine" data-line-num="28"> ssl_session_timeout 10m;</span> <span class="code-block-extension-codeLine" data-line-num="29"> add_header Strict-Transport-Security "max-age=31536000";</span> <span class="code-block-extension-codeLine" data-line-num="30"> error_page 497 https://$host$request_uri;</span> <span class="code-block-extension-codeLine" data-line-num="31"></span> <span class="code-block-extension-codeLine" data-line-num="32"></span> <span class="code-block-extension-codeLine" data-line-num="33"> #SSL-END</span> <span class="code-block-extension-codeLine" data-line-num="34"></span> <span class="code-block-extension-codeLine" data-line-num="35"> #ERROR-PAGE-START 错误页配置,可以注释、删除或修改</span> <span class="code-block-extension-codeLine" data-line-num="36"> #error_page 404 /404.html;</span> <span class="code-block-extension-codeLine" data-line-num="37"> #error_page 502 /502.html;</span> <span class="code-block-extension-codeLine" data-line-num="38"> #ERROR-PAGE-END</span> <span class="code-block-extension-codeLine" data-line-num="39"></span> <span class="code-block-extension-codeLine" data-line-num="40"> #PHP-INFO-START PHP引用配置,可以注释或修改</span> <span class="code-block-extension-codeLine" data-line-num="41"> include enable-php-74.conf;</span> <span class="code-block-extension-codeLine" data-line-num="42"> #PHP-INFO-END</span> <span class="code-block-extension-codeLine" data-line-num="43"></span> <span class="code-block-extension-codeLine" data-line-num="44"> #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效</span> <span class="code-block-extension-codeLine" data-line-num="45"> include /www/server/panel/vhost/rewrite/domain.com.conf;</span> <span class="code-block-extension-codeLine" data-line-num="46"> #REWRITE-END</span> <span class="code-block-extension-codeLine" data-line-num="47"></span> <span class="code-block-extension-codeLine" data-line-num="48"> # 此处开始</span> <span class="code-block-extension-codeLine" data-line-num="49"> location ^~ / {</span> <span class="code-block-extension-codeLine" data-line-num="50"> error_page 405 = @webman;</span> <span class="code-block-extension-codeLine" data-line-num="51"> try_files /${uri}/index.html /${uri} /${uri}/index.html @webman;</span> <span class="code-block-extension-codeLine" data-line-num="52"></span> <span class="code-block-extension-codeLine" data-line-num="53"> }</span> <span class="code-block-extension-codeLine" data-line-num="54"> ## WEBMAN LOCATION</span> <span class="code-block-extension-codeLine" data-line-num="55"> location @webman {</span> <span class="code-block-extension-codeLine" data-line-num="56"> proxy_set_header X-Real-IP $remote_addr;</span> <span class="code-block-extension-codeLine" data-line-num="57"> proxy_set_header Host $host;</span> <span class="code-block-extension-codeLine" data-line-num="58"> proxy_set_header X-Forwarded-Proto $scheme;</span> <span class="code-block-extension-codeLine" data-line-num="59"> proxy_http_version 1.1;</span> <span class="code-block-extension-codeLine" data-line-num="60"> proxy_set_header Connection "";</span> <span class="code-block-extension-codeLine" data-line-num="61"> if (!-f $request_filename){</span> <span class="code-block-extension-codeLine" data-line-num="62"> proxy_pass http://chat_ai;</span> <span class="code-block-extension-codeLine" data-line-num="63"> }</span> <span class="code-block-extension-codeLine" data-line-num="64"> }</span> <span class="code-block-extension-codeLine" data-line-num="65"> # 此处监听wss,则wss连接地址为 wss://yourdomin.com/wss 可自行定义</span> <span class="code-block-extension-codeLine" data-line-num="66"> location /wss {</span> <span class="code-block-extension-codeLine" data-line-num="67"> proxy_pass http://127.0.0.1:7272;</span> <span class="code-block-extension-codeLine" data-line-num="68"> proxy_http_version 1.1;</span> <span class="code-block-extension-codeLine" data-line-num="69"> proxy_set_header Upgrade $http_upgrade;</span> <span class="code-block-extension-codeLine" data-line-num="70"> proxy_set_header Connection "Upgrade";</span> <span class="code-block-extension-codeLine" data-line-num="71"> proxy_set_header X-Real-IP $remote_addr;</span> <span class="code-block-extension-codeLine" data-line-num="72"> }</span> <span class="code-block-extension-codeLine" data-line-num="73"></span> <span class="code-block-extension-codeLine" data-line-num="74"> # 此处结束</span> <span class="code-block-extension-codeLine" data-line-num="75"></span> <span class="code-block-extension-codeLine" data-line-num="76"></span> <span class="code-block-extension-codeLine" data-line-num="77"></span> <span class="code-block-extension-codeLine" data-line-num="78"> #禁止访问的文件或目录</span> <span class="code-block-extension-codeLine" data-line-num="79"> location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)</span> <span class="code-block-extension-codeLine" data-line-num="80"> {</span> <span class="code-block-extension-codeLine" data-line-num="81"> return 404;</span> <span class="code-block-extension-codeLine" data-line-num="82"> }</span> <span class="code-block-extension-codeLine" data-line-num="83"></span> <span class="code-block-extension-codeLine" data-line-num="84"> #一键申请SSL证书验证目录相关设置</span> <span class="code-block-extension-codeLine" data-line-num="85"> location ~ \.well-known{</span> <span class="code-block-extension-codeLine" data-line-num="86"> allow all;</span> <span class="code-block-extension-codeLine" data-line-num="87"> }</span> <span class="code-block-extension-codeLine" data-line-num="88"></span> <span class="code-block-extension-codeLine" data-line-num="89"> location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$</span> <span class="code-block-extension-codeLine" data-line-num="90"> {</span> <span class="code-block-extension-codeLine" data-line-num="91"> expires 30d;</span> <span class="code-block-extension-codeLine" data-line-num="92"> error_log /dev/null;</span> <span class="code-block-extension-codeLine" data-line-num="93"> access_log /dev/null;</span> <span class="code-block-extension-codeLine" data-line-num="94"> }</span> <span class="code-block-extension-codeLine" data-line-num="95"></span> <span class="code-block-extension-codeLine" data-line-num="96"> location ~ .*\.(js|css)?$</span> <span class="code-block-extension-codeLine" data-line-num="97"> {</span> <span class="code-block-extension-codeLine" data-line-num="98"> expires 12h;</span> <span class="code-block-extension-codeLine" data-line-num="99"> error_log /dev/null;</span> <span class="code-block-extension-codeLine" data-line-num="100"> access_log /dev/null; </span> <span class="code-block-extension-codeLine" data-line-num="101"> }</span> <span class="code-block-extension-codeLine" data-line-num="102"> access_log /www/wwwlogs/domain.com.log;</span> <span class="code-block-extension-codeLine" data-line-num="103"> error_log /www/wwwlogs/domain.com.error.log;</span> <span class="code-block-extension-codeLine" data-line-num="104">}</span> </code></pre> ### 启动服务端 启动前需要注意检查服务器内存大小,`memory.php`中设置的内存大小尽量不大于1/2总内存,但不应小于256M。 使用命令 `php start.php start`开始运行,如需后台运行,使用 `php start.php start -d`。如需停止进程,使用 `php start.php stop`即可。 ### 访问管理后台进行初始化配置 服务端部署后,即可通过 `域名/manage/`访问管理后台。 ## 后台配置 服务端启动完成后,访问管理后台进行初始化配置。 必填设置 1. 设置代理方案 2. Key管理 ## 部署uni-app客户端 ### 访问H5端 访问 `服务端域名`即可。 注意:后台配置项中h5地址需要设置为:`服务端域名/` ### 访问PC端 访问 `服务端域名/web/`即可。 ### 后台配置项说明 在管理后台 `配置管理-基本配置`中有一些系统常用的配置。 注意:配置项修改后,需要先点击后台右上角清理缓存后退出登录重新登录。 上传路径配置:在拓展信息中,修改 `绑定域名`配置项,本地测试默认为 `http://127.0.0.1:8998`,如部署到服务端后,此处修改为服务端域名。 在基本信息中: * 内容安全审查接口开关如开启,该功能调用的是微信内容审查接口,因此需要首先确保系统中的小程序配置正确。 * 代理方案 可选 `反向代理`、`环境代理`、`直接访问`。如选择反向代理,则需要配置你的反代服务器域名。如选择环境代理,则需确保服务端所在环境的代理可用。如选择直接访问,需服务端所在环境可直接访问openai的接口。 在应用信息中:可修改免费体验次数、是否分享获取次数(暂时仅针对小程序)、分享获取次数。 在开放信息中:可设置微信公众号登录、支付以及小程序支付功能是否开启。 ## 同一服务器部署多个服务端 1. 修改配置文件 `config\server.php`中 `listen`的端口,官方主分支默认端口为 `8998`,多个服务端不可冲突,此处须修改为其他端口,如 `8999`。 2. 修改配置文件 `config\plugin\webman\gateway-worker\process.php`中 `gateway.listen`配置项端口,官方主分支默认端口为 `7272`,多个服务端不可冲突,此处须修改为其他端口,如 `7282`。修改该文件中 `register.listen`配置项端口,官方主分支默认端口为 `1236`,多个服务端不可冲突,此处须修改为其他端口,如 `1237`,并同步修改 `gateway.constructor.registerAddress`和 `worker.constructor.registerAddress`中的端口为 `1237`(与上一步修改保持一致的端口)。修改 `startPort`为2400(每增加一个服务端,则增加100,需确保2400-2500端口无占用)。 ![微信图片_20230522230200.jpg](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d848b3ad6c074e4faf8a4c43406e9501~tplv-k3u1fbpfcp-zoom-in-crop-mark:1512:0:0:0.awebp?) 3. 修改 `config\my.php`中的 `redis_queue_name`值,默认为 `send-chat`,为避免不同站点消费进程冲突,此处需重命名,如 `send-chat-re`。 4. nginx的转发配置中端口需同步修改,同时upstream的名称也不可重名。 举例:服务器上已运行一个服务端应用,那么须做如下配置修改: `config\server.php`: <pre><div class="code-block-extension-header"><div class="code-block-extension-headerLeft"><div class="code-block-extension-foldBtn"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M16.924 9.617A1 1 0 0 0 16 9H8a1 1 0 0 0-.707 1.707l4 4a1 1 0 0 0 1.414 0l4-4a1 1 0 0 0 .217-1.09z" data-name="Down"></path></svg></div></div><div class="code-block-extension-headerRight"><span class="code-block-extension-lang">php</span><div class="code-block-extension-copyCodeBtn">复制代码</div></div></div><code class="hljs language-php code-block-extension-codeShowNum" lang="php"><span class="code-block-extension-codeLine" data-line-num="1"><?php</span> <span class="code-block-extension-codeLine" data-line-num="2">/**</span> <span class="code-block-extension-codeLine" data-line-num="3"> * This file is part of webman.</span> <span class="code-block-extension-codeLine" data-line-num="4"> *</span> <span class="code-block-extension-codeLine" data-line-num="5"> * Licensed under The MIT License</span> <span class="code-block-extension-codeLine" data-line-num="6"> * For full copyright and license information, please see the MIT-LICENSE.txt</span> <span class="code-block-extension-codeLine" data-line-num="7"> * Redistributions of files must retain the above copyright notice.</span> <span class="code-block-extension-codeLine" data-line-num="8"> *</span> <span class="code-block-extension-codeLine" data-line-num="9"> * @author walkor<walkor@workerman.net></span> <span class="code-block-extension-codeLine" data-line-num="10"> * @copyright walkor<walkor@workerman.net></span> <span class="code-block-extension-codeLine" data-line-num="11"> * @link http://www.workerman.net/</span> <span class="code-block-extension-codeLine" data-line-num="12"> * @license http://www.opensource.org/licenses/mit-license.php MIT License</span> <span class="code-block-extension-codeLine" data-line-num="13"> */</span> <span class="code-block-extension-codeLine" data-line-num="14"></span> <span class="code-block-extension-codeLine" data-line-num="15">return [</span> <span class="code-block-extension-codeLine" data-line-num="16"> 'listen' => 'http://0.0.0.0:8999', // 修改配置文件`config\server.php`中`listen`的端口,官方主分支默认端口为`8998`,多个服务端不可冲突,此处须修改为其他端口,如`8999`</span> <span class="code-block-extension-codeLine" data-line-num="17"> 'transport' => 'tcp',</span> <span class="code-block-extension-codeLine" data-line-num="18"> 'context' => [],</span> <span class="code-block-extension-codeLine" data-line-num="19"> 'name' => 'webman',</span> <span class="code-block-extension-codeLine" data-line-num="20"> 'count' => cpu_count() * 2,</span> <span class="code-block-extension-codeLine" data-line-num="21"> 'user' => '',</span> <span class="code-block-extension-codeLine" data-line-num="22"> 'group' => '',</span> <span class="code-block-extension-codeLine" data-line-num="23"> 'reusePort' => false,</span> <span class="code-block-extension-codeLine" data-line-num="24"> 'event_loop' => '',</span> <span class="code-block-extension-codeLine" data-line-num="25"> 'stop_timeout' => 2,</span> <span class="code-block-extension-codeLine" data-line-num="26"> 'pid_file' => runtime_path() . '/webman.pid',</span> <span class="code-block-extension-codeLine" data-line-num="27"> 'status_file' => runtime_path() . '/webman.status',</span> <span class="code-block-extension-codeLine" data-line-num="28"> 'stdout_file' => runtime_path() . '/logs/stdout.log',</span> <span class="code-block-extension-codeLine" data-line-num="29"> 'log_file' => runtime_path() . '/logs/workerman.log',</span> <span class="code-block-extension-codeLine" data-line-num="30"> 'max_package_size' => 100 * 1024 * 1024</span> <span class="code-block-extension-codeLine" data-line-num="31">];</span> </code></pre> `config\plugin\webman\gateway-worker\process.php`: <pre><div class="code-block-extension-header"><div class="code-block-extension-headerLeft"><div class="code-block-extension-foldBtn"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M16.924 9.617A1 1 0 0 0 16 9H8a1 1 0 0 0-.707 1.707l4 4a1 1 0 0 0 1.414 0l4-4a1 1 0 0 0 .217-1.09z" data-name="Down"></path></svg></div></div><div class="code-block-extension-headerRight"><span class="code-block-extension-lang">php</span><div class="code-block-extension-copyCodeBtn">复制代码</div></div></div><code class="hljs language-php code-block-extension-codeShowNum" lang="php"><span class="code-block-extension-codeLine" data-line-num="1"><?php</span> <span class="code-block-extension-codeLine" data-line-num="2"></span> <span class="code-block-extension-codeLine" data-line-num="3">use Webman\GatewayWorker\Gateway;</span> <span class="code-block-extension-codeLine" data-line-num="4">use Webman\GatewayWorker\BusinessWorker;</span> <span class="code-block-extension-codeLine" data-line-num="5">use Webman\GatewayWorker\Register;</span> <span class="code-block-extension-codeLine" data-line-num="6"></span> <span class="code-block-extension-codeLine" data-line-num="7">return [</span> <span class="code-block-extension-codeLine" data-line-num="8"> 'gateway' => [</span> <span class="code-block-extension-codeLine" data-line-num="9"> 'handler' => Gateway::class,</span> <span class="code-block-extension-codeLine" data-line-num="10"> 'listen' => 'websocket://0.0.0.0:7282', // 2. 修改配置文件`config\plugin\webman\gateway-worker\process.php`中`gateway.listen`配置项端口,官方主分支默认端口为`7272`,多个服务端不可冲突,此处须修改为其他端口,如`7282`。</span> <span class="code-block-extension-codeLine" data-line-num="11"> 'count' => cpu_count(),</span> <span class="code-block-extension-codeLine" data-line-num="12"> 'reloadable' => false,</span> <span class="code-block-extension-codeLine" data-line-num="13"> 'constructor' => ['config' => [</span> <span class="code-block-extension-codeLine" data-line-num="14"> 'lanIp' => '127.0.0.1',</span> <span class="code-block-extension-codeLine" data-line-num="15"> 'startPort' => 2400,</span> <span class="code-block-extension-codeLine" data-line-num="16"> 'pingInterval' => 25,</span> <span class="code-block-extension-codeLine" data-line-num="17"> 'pingData' => '{"type":"ping"}',</span> <span class="code-block-extension-codeLine" data-line-num="18"> 'registerAddress' => '127.0.0.1:1237', // 同步修改端口:2. 修改配置文件`config\plugin\webman\gateway-worker\process.php`中`register.listen`配置项端口,官方主分支默认端口为`1236`,多个服务端不可冲突,此处须修改为其他端口,如`1237`</span> <span class="code-block-extension-codeLine" data-line-num="19"> 'onConnect' => function () {</span> <span class="code-block-extension-codeLine" data-line-num="20"> },</span> <span class="code-block-extension-codeLine" data-line-num="21"> ]]</span> <span class="code-block-extension-codeLine" data-line-num="22"> ],</span> <span class="code-block-extension-codeLine" data-line-num="23"> 'worker' => [</span> <span class="code-block-extension-codeLine" data-line-num="24"> 'handler' => BusinessWorker::class,</span> <span class="code-block-extension-codeLine" data-line-num="25"> 'count' => cpu_count() * 2,</span> <span class="code-block-extension-codeLine" data-line-num="26"> 'constructor' => ['config' => [</span> <span class="code-block-extension-codeLine" data-line-num="27"> 'eventHandler' => plugin\webman\gateway\Events::class,</span> <span class="code-block-extension-codeLine" data-line-num="28"> 'name' => 'ChatBusinessWorker',</span> <span class="code-block-extension-codeLine" data-line-num="29"> 'registerAddress' => '127.0.0.1:1237', // 同步修改端口:2. 修改配置文件`config\plugin\webman\gateway-worker\process.php`中`register.listen`配置项端口,官方主分支默认端口为`1236`,多个服务端不可冲突,此处须修改为其他端口,如`1237`</span> <span class="code-block-extension-codeLine" data-line-num="30"> ]]</span> <span class="code-block-extension-codeLine" data-line-num="31"> ],</span> <span class="code-block-extension-codeLine" data-line-num="32"> 'register' => [</span> <span class="code-block-extension-codeLine" data-line-num="33"> 'handler' => Register::class,</span> <span class="code-block-extension-codeLine" data-line-num="34"> 'listen' => 'text://0.0.0.0:1237', // 2. 修改配置文件`config\plugin\webman\gateway-worker\process.php`中`register.listen`配置项端口,官方主分支默认端口为`1236`,多个服务端不可冲突,此处须修改为其他端口,如`1237`</span> <span class="code-block-extension-codeLine" data-line-num="35"> 'count' => 1, // Must be 1</span> <span class="code-block-extension-codeLine" data-line-num="36"> 'constructor' => []</span> <span class="code-block-extension-codeLine" data-line-num="37"> ],</span> <span class="code-block-extension-codeLine" data-line-num="38">];</span> <span class="code-block-extension-codeLine" data-line-num="39"></span> </code></pre> nginx配置: <pre><div class="code-block-extension-header"><div class="code-block-extension-headerLeft"><div class="code-block-extension-foldBtn"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M16.924 9.617A1 1 0 0 0 16 9H8a1 1 0 0 0-.707 1.707l4 4a1 1 0 0 0 1.414 0l4-4a1 1 0 0 0 .217-1.09z" data-name="Down"></path></svg></div></div><div class="code-block-extension-headerRight"><span class="code-block-extension-lang">ini</span><div class="code-block-extension-copyCodeBtn">复制代码</div></div></div><code class="hljs language-ini code-block-extension-codeShowNum" lang="ini"><span class="code-block-extension-codeLine" data-line-num="1"># 修改upstream名称,需要确保服务器上全局唯一</span> <span class="code-block-extension-codeLine" data-line-num="2">upstream bkchat {</span> <span class="code-block-extension-codeLine" data-line-num="3"> server 127.0.0.1:8999; # 修改server端口</span> <span class="code-block-extension-codeLine" data-line-num="4"> keepalive 10240;</span> <span class="code-block-extension-codeLine" data-line-num="5">}</span> <span class="code-block-extension-codeLine" data-line-num="6"></span> <span class="code-block-extension-codeLine" data-line-num="7">...</span> <span class="code-block-extension-codeLine" data-line-num="8"></span> <span class="code-block-extension-codeLine" data-line-num="9"></span> <span class="code-block-extension-codeLine" data-line-num="10"># 此处开始</span> <span class="code-block-extension-codeLine" data-line-num="11"> location ^~ / {</span> <span class="code-block-extension-codeLine" data-line-num="12"> error_page 405 = @webman;</span> <span class="code-block-extension-codeLine" data-line-num="13"> try_files /${uri}/index.html /${uri} /${uri}/index.html @webman;</span> <span class="code-block-extension-codeLine" data-line-num="14"></span> <span class="code-block-extension-codeLine" data-line-num="15"> }</span> <span class="code-block-extension-codeLine" data-line-num="16"> ## WEBMAN LOCATION</span> <span class="code-block-extension-codeLine" data-line-num="17"> location @webman {</span> <span class="code-block-extension-codeLine" data-line-num="18"> proxy_set_header X-Real-IP $remote_addr;</span> <span class="code-block-extension-codeLine" data-line-num="19"> proxy_set_header Host $host;</span> <span class="code-block-extension-codeLine" data-line-num="20"> proxy_set_header X-Forwarded-Proto $scheme;</span> <span class="code-block-extension-codeLine" data-line-num="21"> proxy_http_version 1.1;</span> <span class="code-block-extension-codeLine" data-line-num="22"> proxy_set_header Connection "";</span> <span class="code-block-extension-codeLine" data-line-num="23"> if (!-f $request_filename){</span> <span class="code-block-extension-codeLine" data-line-num="24"> proxy_pass http://bkchat;</span> <span class="code-block-extension-codeLine" data-line-num="25"> }</span> <span class="code-block-extension-codeLine" data-line-num="26"> }</span> <span class="code-block-extension-codeLine" data-line-num="27"> # 此处监听wss,则wss连接地址为 wss://yourdomin.com/wss 可自行定义</span> <span class="code-block-extension-codeLine" data-line-num="28"> location /wss {</span> <span class="code-block-extension-codeLine" data-line-num="29"> proxy_pass http://127.0.0.1:7272;</span> <span class="code-block-extension-codeLine" data-line-num="30"> proxy_http_version 1.1;</span> <span class="code-block-extension-codeLine" data-line-num="31"> proxy_set_header Upgrade $http_upgrade;</span> <span class="code-block-extension-codeLine" data-line-num="32"> proxy_set_header Connection "Upgrade";</span> <span class="code-block-extension-codeLine" data-line-num="33"> proxy_set_header X-Real-IP $remote_addr;</span> <span class="code-block-extension-codeLine" data-line-num="34"> }</span> <span class="code-block-extension-codeLine" data-line-num="35"></span> <span class="code-block-extension-codeLine" data-line-num="36"> # 此处结束</span> </code></pre> 注意:多个服务端运行在同一服务器,不可使用开发模式,必须以-d模型运行,否则monitor进程端口会冲突报错。 注意:多服务端运行,gateway进程可能会报错误 `SQLSTATE\[HY000] \[1040] Too many connections in`,这是由于每个进程运行时都独立访问了数据库,导致mysql服务器报错,但不影响运行,具体连接数量上限待测试。 注意:多服务端需要关注 `\memory.php`为每个服务端分配的内存限制大小,超过总内存可能导致服务器宕机。同时需要注意gateway进程与redis进程数量,多服务端需调试到最合适的数量。 # 内容安全 ## 自定义敏感词检测 自定义敏感词在百度内容审核平台文本审核接口调用前进行,当命中违禁词库时会自动取消本次对话,并将命中词汇以 `*`替代后返回前端提示用户修改。 自定义敏感词文件存放在 `服务端/resource/sensitive_words.txt`文件中,如需增改请打开该文件后补充,敏感词之间以 `、`分割。 > 为什么以文件形式实现? > >> 提高效率,敏感词库数据量很大,从数据库中读取影响效率。 >> # 其他Debug ## Nginx配置错误 作者:冲浪网友 链接:https://juejin.cn/post/7226689042406391864 来源:稀土掘金 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 最后修改:2023 年 07 月 30 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏