场景:
服务器1:域控服务器 192.168.0.20
服务器2:office online 服务器 192.168.0.10
服务器3: nginx 服务器 192.168.0.30 端口80 【增加】centos7
配置了office online服务器ip的80端口的转发后在外网访问发现,office online 的访问的静态资源都是 http://192.168.0.10/mv/...的,因此导致无法使用。
方案一:
修改office online 的源码
因为文件较多,需要修改的较多,又可能修改遗漏。
方案二:
增加服务器3 nginx服务器 。
通过nginx代理,增加一个第三方的模块来做html内容替换解决,及在代理曾将
http://192.168.0.10:80 -> 替换为: http://外网ip:80
使用的第三方模块为:
ngx_http_substitutions_filter_module,来实现我们的各种需求。
经过测试,这个模块至少有如下实用功能:
①、支持多次替换
②、支持正则替换
③、支持中文替换
因为需要使用第三方模块,因此需要自己编译nginx 。
下载nginx源码。
nginx newshttp://nginx.org/我选择的最新版的1.21版本。
下载 ngx_http_substitutions_filter_module 源码
解压nginx源码,并将ngx_http_substitutions_filter_module源码解压到目录,如图:
安装依赖:
yum install -y openssl openssl-devel pcre zlib zlib-devel gcc
编译:
auto/configure
--prefix=/software/nginx
--add-module=ngx_http_substitutions_filter_module-master/
make
make install
修改配置文件:
location / {
subs_filter_types text / html text / css text / xml ;
subs_filter http://192.168.0.10:80 http://外网ip;
subs_filter http://192.168.0.10 http://外网ip;
}
启动:
cd /software/nginx/sbin
./nginx
通过外网地址访问,查看网页源码,发现已经替换。
源码以及编译好的文件:
使用centos7编译
链接:https://pan.baidu.com/s/1hI8a4aIbfojXZcqRPRFuAQ
提取码:bwhi
windows10编译x86 32位
nginx包含ngx_http_substitutions_filter_module的编译版本,
编译环境:
vs 2019 nginx-1.23.1 、x86_32 windows10
链接:https://pan.baidu.com/s/14GohnQcDpkWHHCScMlGc7A
提取码:cu8t