MaxKB 如何通过Nginx修改浮框提示文字
在使用MaxKB做第三方嵌入的时候,总会有想Diy前端样式的场景,下面就通过Nginx的方式,实现浮框样式的改变。
一、效果对比
- 修改前:
- 修改后:
- 前后对比:
- 修改了提示文字。
- 去掉了图标后面的白框
下面讲一下该如何实现。其实就是用到了nginx的 “ngx_http_sub_module” 模块实现。
二、安装Nginx
2.1 旧Nginx
在安装之前如果已经有了Nginx,需要查看是否有ngx_http_sub_module模块
nignx -V
如果不支持,则需要安装该模板。需要重新编译一下nginx 的 bin文件然后重新替换。
找到nginx的安装包,然后重新执行configure编译,例如:
# 如果已经有了很多模块,在编译的时候都需要加上。
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module
make # 注意不要使用 make install,以免覆盖现有安装
#替换二进制文件(这里展示的默认安装路径,实际根据自己路径替换。)
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak # 备份原文件
cp ./objs/nginx /usr/local/nginx/sbin/
2.2 新安装Nginx
nginx-1.26.2.tar.gz
1. 下载安装包到服务器上
2. 解压
tar -zxvf nginx-1.26.2.tar.gz
3. 编译nginx
cd nginx-1.26.2
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module
make & make install
2.3 添加html_nginx.conf配置文件
此处需要把maxkb嵌入的第三方链接地址给写进来。
1. 创建新的配置文件html_nginx.conf
server {
listen 9999;
server_name localhost;
# 核心配置:代理与CSS替换
location /api/application/embed {
# 反向代理配置
proxy_pass http://democenter.fit2cloud.cn:28090/api/application/embed?protocol=http&host=democenter.fit2cloud.cn:28090&token=123456;
# 强制禁用压缩传输
proxy_set_header Accept-Encoding "";
proxy_redirect off;
# 内容替换配置
sub_filter_types *;
sub_filter 'mask_content.style.width = chat_button_img.width ' 'mask_content.style.width = "0" ';
sub_filter 'mask_content.style.height = chat_button_img.height ' 'mask_content.style.height= "0" ';
sub_filter '🌟 遇见问题,不再有障碍!' '🌟 点我咨询';
sub_filter '你好,我是你的智能小助手。' '我是你的专业助手';
sub_filter '点我,开启高效解答模式,让问题变���过去式。' '有什么问题都可以咨询我';
sub_filter_once off;
# 代理基础配置
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_no_cache 1;
proxy_cache_bypass 1;
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
}
其中主要的是内容替换配置的这部分
重新执行nginx
nginx -t
nginx -s reload
验证一下使用代理地址是否能够打开页面
三、修改嵌入链接
3.1 修改嵌入地址
复制浮框模式的代码:
去到自己的网页,把src的路径修改为自己的代理路径