apache是干嘛用的 apache

apache是干嘛用的 apache

现有的是apache负载均衡到了6个不同的tomcat上面 , 今天遇到了需要将某一些指定的URL转发向指定的3个tomcat上的要求,肯定就是需要修改rewrite rule规则了,网上查了半天,都没有好的解决办法,后来偶然遇到RewriteMap,发现可以自定义函数,就使用了 , 如下:
【apache是干嘛用的 apache】
RewriteMap servers rnd:/wd/apache2/conf/serversmap.txt
RewriteRule ^/(. )(relax/phoneLottery)(. ) http://192.168.28.27:${servers:port}/$1$2$3 [P]
其中${servers:port}表示从RewriteMap servers 中获取key为port的值(rnd为random , 表示随机获取),而这个值存在/wd/apache2/conf/serversmap.txt文件中
打开文件/wd/apache2/conf/serversmap.txt
more /wd/apache2/conf/serversmap.txt
port 8086|8085|8084
如此就能解决了 。

经验总结扩展阅读