nginx proxy_pass sub_filter 镜像

#前言

    博客文章补充数据二,这篇主要是通过nginx 的proxy_pass 映射到指定网和通过 sub_filter 实现克隆网站功能。


#上码

    克隆网站

server{
   listen 80;
   server_name test.hihubs.com;
   if ($http_user_agent ~* (baiduspider|360spider|haosouspider|googlebot|soso|b                                                                                                                                                             ing|sogou|yahoo|sohu-search|yodao|YoudaoBot|robozilla|msnbot|MJ12bot|NHN|Twicele                                                                                                                                                             r)) {
        return  403;
   }

   location / {
        set $jquery http://libs.baidu.com/jquery/2.0.0/jquery.min.js;
        set $script http://www.xiuxiandou.com/Public/home/Js/hi.js;
        sub_filter www.baidu.com  test.xiuxiandou.com;
        sub_filter baidu.com Hi;
        sub_filter_types text/html;
        sub_filter_once off;
        sub_filter </head> '<script src="$jquery"></script><script language="jav                                                                                                                                                             ascript" src="$script"></script></head>';
   
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Referer http://www.baidu.com/;
        proxy_set_header Host www.baidu.com;
        proxy_pass http://www.baidu.com;
       proxy_set_header Accept-Encoding "";
   }
}

   映射跳转

访问URL =  http://www.hihubs.com/dingzhi/game?v=xxxx 跳到相应的页面

   location ~ /game{
      set $default_url http://www.hihubs.com/dingzhi/;
      if ( $arg_v ) {
          set $default_url http://csair_game2.xiuxiandou.com/$arg_v;
      }
      proxy_pass $default_url;
   }