Apache 代理(Proxy)

代理分为:正向代理(Foward Proxy)和反向代理(Reverse Proxy)

 

1、正向代理(Foward Proxy)

 

正向代理(Foward Proxy)用于代理内部网络对Internet的连接请求,客户机必须指定代理服务器,并将本来要直接发送到Web服务器上的http请求发送到代理服务器,由代理服务器负责请求Internet,然后返回Internet的请求给内网的客户端。

 

Internal Network Client ——(request-url)——> Foward Proxy Server ———— > Internet

 

2、反向代理(Reverse Proxy)

 

反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个服务器。如图:

 

/————> Internal Server1

Internet ————> Reverse Proxy Server  ————> Internal Server2

\————> internal serverN

 

Apache 代理

 

apache支持正向代理和反向代理,但一般反向代理使用较多。

 

 

#正向代理

# 正向代理开关
ProxyRequests On
ProxyVia On

<Proxy *>
Order deny,allow
Deny from all
Allow from internal.example.com
</Proxy>
 

 

 

# Reverse Proxy

# 设置反向代理
ProxyPass /foo http://foo.example.com/bar
# 设置反向代理使用代理服务的HOST重写内部原始服务器响应报文头中的Location和Content-Location
ProxyPassReverse /foo http://foo.example.com/bar
 

   注意:ProxyPassReverse 指令不是设置反向代理指令,只是设置反向代理重新重定向(3xx)Header头参数值。

 

举例:

 

下面是典型的APACHE+TOMCAT负载均衡和简单集群配置

 

    ProxyRequests Off  
    ProxyPreserveHost on 
    
    ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=Off
    ProxyPassReverse / balancer://cluster/  
    <Proxy balancer://cluster>  
      BalancerMember  http://localhost:8080 loadfactor=1 retry=10  
      BalancerMember  http://localhost:8081 loadfactor=1 retry=10  
      ProxySet lbmethod=bybusyness  
    </Proxy>

 

    ProxyPassReverse / balancer://cluster/ 表示负载均衡配置中的所有TOMCAT服务器,如果响应报文的Header中有Location(3xx指定重定向的URL)或Content-Location(指定多个URL指向同一个实体),则使用请求报文中HOST替换URL中的HOST部分。

 

 

  1. GET http://apache-host/entityRelativeUrl
  2. tomcat response 307 ,Header Location: http://localhost:8080/entityRelativeUrl
  3. apache 重写 response header中的Location为:http://apache-host:8080/entityRelativeUrl

 

注意:只有TOMCAT RESPINSE Location中的URL的Host部分匹配tomcat原始HOST的情况才重写。如307到http://localhost:8088/entityRelativeUrl是不会重写的。

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zp820705

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值