首页
导航
博客
电子书
算法
众创
代码
随贴
关于我们
您好,欢迎来到码863代码分享网! 请
[登录]
/
[注册]
搜 索
标题:
*
140
字
TAG标签:
(用空格隔开)
30
字
恢复历史版本:
请选择分类
html
python
javascript
php
sql
c
c++
c#
java
plain
所有人可见
仅自己可见
编辑器:UEditor
编辑器:TinyMCE
编辑器:Editor.md
HTML转MD
HTML转MD2
<p><a href="https://blog.csdn.net/xiaoyao8903/article/details/53244900">https://blog.csdn.net/xiaoyao8903/article/details/53244900</a> </p><p><br/></p><p>lnmp.org 脚本本身安装好了 直接用 害我搞好久 <span style="color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; background-color: rgb(255, 255, 255);">sub_filter_once off;</span></p><p><br/></p><p><br/></p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">Nginx是一款轻量级高性能服务器软件,虽然轻量,但功能非常强大,可用于提供WEB服务、反向代理、负载均衡、缓存服务、甚至可以通过添加一些模块搭建rtmp流媒体服务。最近碰到一个客户需求,需要用到nginx网页内容替换模块,以下是相关实验记录,贴出来跟大家交流,如有不足之处请指出。</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">ngx_http_sub_module模块是一个过滤器,它修改网站响应内容中的字符串。这个模块已经内置在nginx中,但是默认未安装,需要安装需要加上配置参数:--with-http_sub_module 如果已经安装nginx,只需要再添加这个模块就可以了。</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">一、安装:</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">nginx官网下载安装包:http://nginx.org/en/download.html</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);"># wget http://nginx.org/download/nginx-1.11.5.tar.gz</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);"># tar -zxvf nginx-1.11.5.tar.gz</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);"># cd nginx-1.11.5</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);"># ./configure --with-http_stub_status_module --with-http_sub_module && make && make install</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">二、常用指令:</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">2.1 sub_filter指令: sub_filter string(原字符串) replacement(用于替换的字符串);</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">用于设置需要使用说明字符串替换说明字符串.string是要被替换的字符串,replacement是 新的字符串,它里面可以带变量。</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">2.2 sub_filter_last_modified指令: sub_filter_last_modified on | off;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">用于设置网页内替换后是否修改 可在nginx.conf的 http, server, location三个位置配置使 用,默认值是off;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">2.3 sub_filter_once指令:sub_filter_once on | off;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">用于设置字符串替换次数,默认只替换一次。如果是on,默认只替换第一次匹配到的到字 符,如果是off,那么所有匹配到的字符都会被替换;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">2.4 sub_filter_types指令:sub_filter_types *</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">用于指定需要被替换的MIME类型,默认为“text/html”,如果制定为*,那么所有的;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">说明:以上指令可在nginx.conf的http, server, location三个位置配置使用;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">三、反向代理动态替换网页内容实例参考:</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">upstream www.iptest.cn {</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">server 118.184.180.46:80;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">}</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">#反向代理,如果有多个服务端ip,还可以添加负载均衡方式,权重等策略#</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">server {</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">listen 80;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">#监听端口#</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">server_name www.iptest.cn;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">#设置server name#</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">charset utf-8;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">#设置字符编码为utf-8,可根据实际情况调整#</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">location / {</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">proxy_pass http://www.iptest.cn$request_uri;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">#反向代理规则#</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">proxy_set_header Accept-Encoding deflate;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">#设置反向代理头部,有时候源站响应的是gzip格式,替换的时候会有问题,可通过此项解决#</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">subs_filter '183.251.160.127' '123.181.128.17';</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">#替换指定ip,此处将183.251.160.127替换成123.181.128.17#</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">subs_filter '福建省龙岩市 移动' '河北省唐山市 电信';</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">#替换城市、运营商信息,nginx此替换模块支持中文替换#</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">subs_filter_types text/html;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">#指定被替换的MIME类型#</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">sub_filter_once on;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">#指定字符串替换次数,on表示只替换第一次匹配到的字符,off表示替换所有匹配到的字符#</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">}</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">}</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">说明:</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">1、此模块替换不区分大小写;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">2、支持中文替换;</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">Nginx.conf 完整配置:</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);"><img src="http://p3.pstatp.com/large/10200000bdb33d67797a" alt="使用Nginx反向代理和内容替换模块实现网页内容动态替换功能" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; max-width: 100%; overflow-wrap: break-word; cursor: zoom-in; border: 0px; display: block;"/></p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">实验效果截图:</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);"><img src="http://p3.pstatp.com/large/f7a0001c934632669a5" alt="使用Nginx反向代理和内容替换模块实现网页内容动态替换功能" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; max-width: 100%; overflow-wrap: break-word; cursor: zoom-in; border: 0px; display: block;"/></p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);"><img src="http://p3.pstatp.com/large/10230000bd0c9e8fbbcf" alt="使用Nginx反向代理和内容替换模块实现网页内容动态替换功能" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; max-width: 100%; overflow-wrap: break-word; cursor: zoom-in; border: 0px; display: block;"/></p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">结束语:</p><p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; color: rgb(34, 34, 34); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255);">另外一个类似的内容替换模块nginx_substitutions_filter,有兴趣的可以做下实验玩玩。</p><p><br/></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p><p>https://www.cnblogs.com/cyq632694540/p/7132778.html</p><p style="margin: 10px auto;">nginx之所以轻,因为默认没有安装各种各样的扩展;</p><p style="margin: 10px auto;">nginx安装扩展插件:</p><p style="margin: 10px auto;">下面列出两个可能会用到的插件</p><p style="margin: 10px auto;">一、sub_filter内容过滤器,这个在nginx做http转发的时候会很常用</p><p style="margin: 10px auto;">1.下载插件>git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git</p><p style="margin: 10px auto;"><img src="/ueditor/php/upload/image/20200103/1578056134129092.png" alt="" style="border: 0px; max-width: 900px; height: auto;"/></p><p style="margin: 10px auto;"> </p><p style="margin: 10px auto;">2.安装插件</p><p style="margin: 10px auto;">**如果你还没有安装nginx的,配置的时候./configure ..... 加上 --add-module=/tmp/ngx_http_substitutions_filter_module 这段话进行配置;</p><p style="margin: 10px auto;"> </p><p style="margin: 10px auto;">**如果你已经安装了nginx的,找到你的nginx源安装目录如</p><p style="margin: 10px auto;">>cd nginx-1.11.0 //进入nginx安装目录</p><p style="margin: 10px auto;">>./configure --prefix=/usr/local/nginx --add-module=/tmp/cyq/ngx_http_substitutions_filter_module //prefix指定你安装好的nginx目录,add-module指定你下载的sub_filter插件目录</p><p style="margin: 10px auto;"><img src="/ueditor/php/upload/image/20200103/1578056134148362.png" alt="" style="border: 0px; max-width: 900px; height: auto;"/></p><p style="margin: 10px auto;">>make //这边注意了,不要make install,只需要make编译一下,然后在当前目录的./objs/下面就会更新nginx启动文件</p><p style="margin: 10px auto;"><img src="/ueditor/php/upload/image/20200103/1578056134146356.png" alt="" style="border: 0px; max-width: 900px; height: auto;"/> </p><p style="margin: 10px auto;">>mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old //先pkill -9 nginx 停止nginx服务</p><p style="margin: 10px auto;">>cp ./objs/nginx /usr/local/nginx/sbin/nginx //把编译生成的文件放到你的nginx启动目录里面</p><p style="margin: 10px auto;">>/usr/local/nginx/sbin/nginx //启动nginx就行了</p><p style="margin: 10px auto;"><img src="/ueditor/php/upload/image/20200103/1578056134938054.png" alt="" style="border: 0px; max-width: 900px; height: auto;"/></p><p style="margin: 10px auto;"> </p><p style="margin: 10px auto;">3.打开自己的网站,内容是 this is php in 192.168.199.167</p><p style="margin: 10px auto;"><img src="/ueditor/php/upload/image/20200103/1578056134356020.png" alt="" style="border: 0px; max-width: 900px; height: auto;"/></p><p style="margin: 10px auto;"> </p><p style="margin: 10px auto;">在对应的nginx.conf 文件中,添加需要进行过滤的数据内容</p><p style="margin: 10px auto;">vi nginx.conf</p><p style="margin: 10px auto;"><img src="/ueditor/php/upload/image/20200103/1578056134189113.png" alt="" style="border: 0px; max-width: 900px; height: auto;"/></p><p style="margin: 10px auto;"> 将this is 改为 my name is</p><p style="margin: 10px auto;"><img src="/ueditor/php/upload/image/20200103/1578056134729534.png" alt="" style="border: 0px; max-width: 900px; height: auto;"/></p><p style="margin: 10px auto;"> </p><p style="margin: 10px auto;"> 是不是很强大呢?毕竟nginx是属于第七层应用层领域的,所以转发的内容可以随意修改;这个插件可以用于建设小偷网站,就是域名是自己的,但是你转发到其他网站的时候,里面很多数据都暴露了网站内容属于其他人的</p><p style="margin: 10px auto;">这个时候你就可以使用sub_filter来做内容过滤了!哈哈哈哈!</p><p style="margin: 10px auto;"> </p><p style="margin: 10px auto;"> </p><p style="margin: 10px auto;"> </p><p style="margin: 10px auto;">二、nginx无法转发到https网站</p><p style="margin: 10px auto;">会报以下错误:</p><p style="margin: 10px auto;">nginx: [emerg] https protocol requires SSL support in xx/xxx/xx/</p><p style="margin: 10px auto;">这个很简单,不过网上说什么缺少ssl模块啦,还要安装证书啦,巴拉巴拉一大堆。(这些只是针对网站需要证书验证访问才需要的)</p><p style="margin: 10px auto;">一般的访问https失败,只是因为nginx没有安装两个模块http_ssl_module和http_stub_status_module </p><p style="margin: 10px auto;">解决步骤:</p><p style="margin: 10px auto;">1.进入nginx安装目录</p><p style="margin: 10px auto;">>cd /xx/nginx-1.11.0</p><p style="margin: 10px auto;">>./configure --with-http_stub_status_module --with-http_ssl_module</p><p style="margin: 10px auto;">>make</p><p style="margin: 10px auto;">>cp ./objs/nginx /usr/local/nginx/sbin/nginx //先停止nginx,然后吧nginx覆盖掉</p><p style="margin: 10px auto;">>/usr/local/nginx/sbin/nginx //再次启动nginx就可以了</p><audio controls="controls" style="display: none;"></audio>
CopyRight 2002~2023 精通2100网 联系邮箱:qqtxt@163.com
版权所有:精通2100网
湘ICP备2023018646号-1
MYSQl共执行 4 个查询,用时 0.0023088455200195 秒,PHP脚本用时 0.005035 秒,占用内存 0.738 MB,Gzip 已启用