Atitit.实现反向代理(1)----url rewrite 配置and内容改写 and -绝对路径链接改写 java php

Atitit.实现反向代理(1)----url rewrite  配置and内容改写 and -绝对路径链接改写 java php

1. 代理的实现:::普通代理and反向代理??
1

2. url rewrite 的框架选型 1

3. ---------反向代理rewrite 配置mode_rewrite 1

1. Java的实现 2

4. 排除自身(apache_mode_rewrite) 2

2. Java的实现 排除自身 2

5. 内容改写(php mode_rwt) 3

3. Java 内容改写 3

6. 内容改写---绝对路径链接改写 4

4. Abs url 2 /app/http://xxxxxx.jpg 4

5. Filter 二次导航 4

6. 判断and代替改写 5

7. 引用 6

1. 代理的实现:::普通代理and反向代理??

普通代理设置麻烦的,韩式反向代理容易的实现..

反向代理使用流程:: localhost/vod/    >>url rewrite   >>>内容更改

2. url rewrite 的框架选型

Php的mode_rewrite好的...java的org.tuckey.web.filters.urlrewrite.UrlRewriteFilter 不太好使用,,,子好嘎自实现兰...

作者::老哇的爪子Attilax艾龙,EMAIL:[email protected]

转载请注明来源:http://blog.csdn.net/attilax

3. ---------反向代理rewrite 配置mode_rewrite

RewriteCond %{REQUEST_URI} !=/process.php

RewriteRule  ^(.*)$    /process.php?file=http://www.budejie.com/$1&noext=1 [L] [L]

1. Java的实现

<!--o8j2   -->

<filter>

<filter-name>urlrwt</filter-name>

<filter-class>com.attilax.net.urlRewriteFilterAti</filter-class>

</filter>

<filter-mapping>

<filter-name>urlrwt</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<!-- end o8j2-->

RequestDispatcher requestDispatcher = request.getRequestDispatcher("/spr/txtrwt?url="+url+"&urlNoHost="+url_noHost2);

requestDispatcher.forward(request, response);//

4. 排除自身(apache_mode_rewrite)

RewriteCond %{REQUEST_URI} !=/process.php

RewriteCond %{REQUEST_URI} !^.*(\.js|\.gif|\.png|\.jpg|\.jpeg|\.xml|\.ico|\.css)

#other pic css js proxy

RewriteCond %{REQUEST_URI} !=/process.php

RewriteCond %{REQUEST_URI} !=/lensyaohwer/basic.png

RewriteRule  ^(.*)$    http://lengxiaohua.com/$1 [P,L]

2. Java的实现 排除自身

//except

if(requestURI.contains("spr/txtrwt"))

{

chain.doFilter(request, response);

return;

}

5. 内容改写(php mode_rwt)

a.文本正则表达式方式

$content=preg_replace(‘/百思不得姐/‘, ‘哈米‘, $content);

$content=str_replace(‘http://img.spriteapp.cn/ws/www/img/layout/logo.png‘, ‘http://img.spriteapp.cn/ws/www/img/layout/logoxx.png‘, $content);

$content=str_replace(‘不得姐‘, ‘哈米‘, $content);

b.html dom 方式

//nbp

require_once  "simple_html_dom.php";

$html = str_get_html($content);

$arr= $html->find(‘.web_content_right .web_right_down‘,0) ;

$arr->innertext=‘a2‘;

echo  $html ;

3. Java 内容改写

@RequestMapping(value = "/txtrwt", produces = "text/plain;charset=gb2312")

// @ResponseBody

public Object process(HttpServletRequest request,

HttpServletResponse response) throws Exception {

core.log("=========process.json");

String url = "" + request.getParameter("url");// +"?"+request.getQueryString();

String url_no_host=request.getParameter("urlNoHost");

// System.out.println(); request.getParameter("tid")

System.out.println(request.getQueryString());

if (url.endsWith("jpg") || url.endsWith("jpeg") || url.endsWith("gif")) {

if(url_no_host.startsWith("/http://"))

{

String url3=url_no_host.replaceAll("/http://", "http://");

byte[] ba = websitex.WebpageContent_Bin(url3);

if( !isLjJpg(ba) )

outputImg(response, url);

}

else

outputImg(response, url);

}

//

else

outputTxt(response, url,request);

return null;

}

6. 内容改写---绝对路径链接改写

4. Abs url 2 /app/http://xxxxxx.jpg

private void outputTxt(HttpServletResponse response, String url, HttpServletRequest request)

throws UnsupportedEncodingException, IOException {

Map<String, String>  headProps =  Mapx

.<String, String> $()

.add("Cookie",

"lastfid=0; lastvisit=9271%091408838229%09%2Fread.php%3Ftid%3D1715718%26fpage%3D2; ol_offset=32204; ipstate=1408836660; __utma=99888095.1396678057.1405101634.1408806230.1408837132.29; __utmz=99888095.1405101634.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmc=99888095; pin6=done; __utmb=99888095.3.10.1408837132")

.toMap() ;

String txt=websitex.WebpageContentO8f  (url,"gbk",headProps);

txt=txt.replaceAll("http://", pathx.webAppPath_webfmt(request)+ "/http://");

5. Filter 二次导航

if(url_noHost.startsWith("/http://"))

{

String url5=url_noHost.substring(1, url_noHost.length());

String url5_encode= URLEncoder.encode(url5);

RequestDispatcher requestDispatcher = request.getRequestDispatcher("/spr/imgrwt_abspath?url="+url5_encode+"&urlNoHost="+url_noHost2);

requestDispatcher.forward(request, response);//

return;

}

6. 判断and代替改写

@RequestMapping(value = "/imgrwt_abspath")

// @ResponseBody

public Object process_imgrwt_abspath(HttpServletRequest request,

HttpServletResponse response) {

core.log("=========process.json");

String url = "" + request.getParameter("url");// +"?"+request.getQueryString();

String url_no_host = request.getParameter("urlNoHost");

// System.out.println(); request.getParameter("tid")

System.out.println(request.getQueryString());

byte[] ba = websitex.WebpageContent_Bin(url);

if (!isLjJpg(ba))

outputImg(response, url);

if(isLjJpg(ba))

outputImg_garfile_holder(response );

return null;

}

/**

@author attilax 老哇的爪子

\[email protected]  Aug 23, 2014 8:48:02 PM$

* @param response

*/

private void outputImg_garfile_holder(HttpServletResponse response) {

// attilax 老哇的爪子 8:48:02 PM Aug 23, 2014

{

String url = pathx.classPath() + "/com/attilax/clr/def.jpg";

byte[] ba = filex.readImageData(url);

outputImg(response, url, ba);

}

}

7. 引用

paip.基于urlrewrite的反向代理以及内容改写

时间: 2024-08-06 20:01:02

Atitit.实现反向代理(1)----url rewrite 配置and内容改写 and -绝对路径链接改写 java php的相关文章

FastDFS + Nginx 反向代理缓存 安装与配置

FastDFS + Nginx 反向代理缓存 安装与配置 作者:斯巴达克斯 时间:March 26, 2015 分类:存储 操作系统 CentOS release 6.5 (Final) 64 nginx相关软件 nginx-1.4.7 下载地址: http://nginx.org/en/download.html#nginx清除缓存模块 ngx_cache_purge-2.1 http://labs.frickle.com/nginx_ngx_cache_purge/pcre-8.36 ftp

Nginx反向代理实现负载均衡配置图解

[导读] 负载均衡配置是超大型机器需要考虑的一些问题,同时也是数据安全的一种做法,下面我来介绍在nginx中反向代理 负载均衡配置图解,大家可参考本文章来操作. 首先简单的介绍下nginx作为反向代理实现负载均衡.反向负载均衡配置是超大型机器需要考虑的一些问题,同时也是数据安全的一种做法,下面我来介绍在nginx中反向代理 负载均衡配置图解,大家可参考本文章来操作. 首先简单的介绍下nginx作为反向代理实现负载均衡. 反向代理方式是指以反向代理服务器来接受互联网上的连接请求,然后将请求转发给内

nginx 反向代理http和https配置

nginx可以反向代理http,同样也可以代理https,只是需要ssl证书.这里推荐一个好用的证书: https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E 步骤非常详细. 安装nginx 参照: http://mrdeng.blog.51cto.com/3736360/1735313 编译的时候需要制定ssl模块: --with-http_ssl_module ,启用nginx对ssl的支持. 安装完成之后,配置反向代理的ngi

nginx 反向代理实现负载均衡*配置实战

(接理论篇) 查看lb01的配置文件如下: cat /usr/local/nginx/conf/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream www_server_pools { #默认调度算

nginx反向代理功能及常用配置

反向代理指的是用代理服务器来响应客户端的请求,然后根据一定的调度算法将请求发送到后端服务器,当后端服务器处理完请求后,再将请求处理的结果发送给反向代理服务器,由代理服务器将处理结果发送给客户端的一种数据请求模式.Nginx作为近年来比较火的反向代理服务器,主要用于转发客户机请求,后台有多个http服务器提供服务,nginx的功能就是把请求转发给后面的服务器,决定哪台目标主机来处理当前请求. 后端的服务器我们在这里称为upstream server,在上图所示中,中间的反向代理服务器,首先自己扮演

Nginx反向代理2--配置文件配置

2.1Nginx的反向代理 什么是正向代理? 1.2   使用nginx实现反向代理 Nginx只做请求的转发,后台有多个http服务器提供服务,nginx的功能就是把请求转发给后面的服务器,决定把请求转发给谁. 1.2.1   安装tomcat 在一个虚拟机上创建两个tomcat实例,模拟多个服务器. 1.2.2   需求 通过访问不同的域名访问运行在不同端口的tomcat 8080.itheima.com   访问运行8080端口的tomcat 8081.itheima.com   访问运行

Nginx反向代理以及负载均衡配置

前提:最近在研究nginx的用法,在windows上小试了一下,由于windows下不支持nginx缓存配置,所以本文主要是讲nginx,以及反向代理与负载均衡. [一.为什么要使用nginx] 要回答为什么要使用nginx,那就先说说nginx能做些什么. 首先,nginx能做反向代理,那么什么是反向代理呢,举个栗子,我想在本地使用 www.mickey.com 的域名去访问 www.taobao.com.那么这个时候我们就可以通过nginx去实现. 再者,nginx能实现负载均衡,什么是负载

Nginx反向代理,负载均衡配置

主配置文件:nginx.conf # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user www; worker_processes 2; error_log /var/log/nginx/error.lo

Apache上配置反向代理以及负载均衡配置

之前一个项目需要在Apache上配置负载均衡,由于事情繁多,时间紧迫,没有时间去弄. 今天抽时间测试了一把,至少是可以进行代理了. 现将如何配置反向代理和负载均衡分别描述. 1.反向代理 步骤: (1)在Apache的配置文件httpd.conf中打开反向代理的模块 #----------------------------------------------- LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_conne