ProxyRequests Off //使用ProxyRequests指令即可激活正向代理
<Proxy your_apache(Unix平台最流行的WEB服务器平台)_server_ip:80>
Order deny,allow
Allow from all
</Proxy>
然后新建一个网站,即创建一个标准的<virtualhost>配置段。这里我们将站点/test目录设置为google的反向代理。加入下边内容:
ProxyPass /images/ !
ProxyPass /js/ !
ProxyPass /css/ !
ProxyPass / http://192.168.1.101/
ProxyPass /test1 http://192.168.1.102/
ProxyPass /test http://www.google.com/
ProxyPassReverse /test http://www.google.com/
ProxyPass易理解,就是转发url上的请求.其中的配置顺序也是需要遵守 。要禁止转发的url需要放在一般的请求之前。对于http://***/images/ http://***/js/http://***/css/的请求是不予转发的,对于http://***/test1/的请求,会转发到 http://192.168.1.102/。ProxyPassReverse就是反向代理
然后保存配置文件重新启动apache
通过反向代理,我们可以将web服务器放置在防火墙后,在web服务器前端使用mod_proxy配置反向代理,并打开apache(Unix平台最流行的WEB服务器平台)的mod_cache缓存模块,更可以极大的提高对静态内容的访问性能。
--------------理解反向代理:
<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy localhost:80>
#AddDefaultCharset off
Order deny,allow
Deny from all
#Allow from .example.com
</Proxy>
ProxyPass /it http://192.168.1.117/2222
</IfModule>
访问http://192.168.1.102/it/a==>直接跳转http://192.168.1.117/2222/a/
<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy localhost:80>
# AddDefaultCharset off
Order deny,allow
Deny from all
#Allow from .example.com
</Proxy>
ProxyPass /it http://192.168.1.117/2222
ProxyPassReverse /it http://192.168.1.117/2222
</IfModule>
访问http://192.168.1.102/it/a==>http://192.168.1.102/it/a/
<Location /s-server-status>
SetHandler server-status
Order deny,allow
# Deny from all
Allow from 192.168.1.117
# ip6-localhost
# Allow from .example.com
</Location>
<Location /server-info>
SetHandler server-info
Order Deny,Allow
#Deny from all
Allow from 192.168.1.117
</Location>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
#Deny from all
Allow from 192.168.1.117
</Location>