php是最好的语言

nginx实现反向代理网站并且替换网站内容

在原来nginx基础上新增

ngx_http_substitutions_filter_module(http://www.cnblogs.com/dudu/p/nginx-subs_filter.html)模块和

replace-filter-nginx-module(http://www.360doc.com/content/17/0611/23/597197_661995547.shtml)模块


replace-filter-nginx-module相关函数知识http://www.cnblogs.com/jimodetiantang/p/9486116.html

如下配置(可以访问test.phpindex.win看效果,也可以买个非大陆的服务器用来翻墙)


 ## Start 16.32 ##
server {
    listen 80;
    server_name  test.phpindex.win;
 
#    access_log  logs/proxy34.access.log  main;
#    error_log  logs/proxy34.error.log;
    root   html;
    index  index.html index.htm index.php;
 
    ## send request back to 16.32 ##
    location / {
        proxy_pass  http://phpindex.win/;
 
        #Proxy Settings
        #proxy_redirect     off;   #替换location会用到 302跳转
        proxy_set_header   Host  www.phpindex.win;  #           $host;不能使用$host变量
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;

#        proxy_set_header REMOTE-HOST $remote_addr;

#        subs_filter <sup>.*?</sup> <sup>被替换了</sup> gr;
         subs_filter  www.phpindex.win test.phpindex.win;

         replace_filter '<header>([\s\S]*?)</header>' '<header>$1<p style="width: 100px;height: 100px;color: black;position: fixed;background: #ffe403;">这就是网站劫持</p></header>' ig;
         replace_filter_types text/plain text/css;
#         replace_filter  <body>([\s\S]*)</body> <sub>111$1324324</sub> ig;

   }
}


作者:xTao 分类:LNMP 浏览:2946 评论:0