日期:2014-05-17  浏览次数:20875 次

关于apache模块mod_proxy中ProxyPass和ProxyPassReverse指令

?? 对应详细使用说明如下:
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
(一).ProxyPass 指令

说明: 将一个远端服务器映射到本地服务器的URL空间中
语法: ProxyPass [路径] !|url
上下文: 服务器配置, 虚拟主机
状态: Extension
模块: mod_proxy

指令对于您不想对某个子目录进行反向代理时很有用。比如说:

ProxyPass /mirror/foo/i !
ProxyPass /mirror/foo http://foo.com

将会代理除对/mirror/foo/i请求之外的所有对 foo.com 的/mirror/foo请求。

注意:顺序很重要,您需要把特例情况放在一般代理通过指令
当在<Location>配置段中使用时,第一个参数会被忽略而是采用由<Location>指令指定的本地目录。

如果您需要一个更加灵活的反向代理配置,请参见使用[P]标记的RewriteRule指令。

?

(二).ProxyPassReverse 指令

说明: 调整由反向代理服务器发送的HTTP回应头中的URL
语法: ProxyPassReverse [路径] url
上下文: 服务器配置, 虚拟主机
状态: Extension
模块: mod_proxy

此指令使 Apache 调整HTTP重定向回应中Location, Content-Location和URI头里的URL。 HTTP redirect responses. This is essential when Apache is used as a reverse proxy to avoid by-passing the reverse proxy because of HTTP redirects on the backend servers which stay behind the reverse proxy.

路径是本地虚拟路径的名称。
url远端服务器的部分URL。与ProxyPass指令中的使用方法相同。

示例:
假定本地服务器拥有地址http://wibble.org/;那么

ProxyPass /mirror/foo/ http://foo.com/
ProxyPassReverse /mirror/foo/ http://foo.com/

will not only cause a local request for the <http://wibble.org/mirror/foo/bar> to be internally converted into a proxy request to <http://foo.com/bar> (the functionality ProxyPass provides here). It also takes care of redirects the server foo.com sends: when http://foo.com/bar is redirected by him to http://foo.com/quux Apache adjusts this to http://wibble.org/mirror/foo/quux before forwarding the HTTP redirect response to the client. Note that the hostname used for constructing the URL is chosen in respect to the setting of the UseCanonicalName directive.

Note that this ProxyPassReverse directive can also be used in conjunction with the proxy pass-through feature ("RewriteRule ... [P]") from mod_rewrite because its doesn't depend on a corresponding ProxyPass directive.

When used inside a <Location> section, the first argument is ommitted and the local directory is obtained from the <Location>.
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
(三).实际问题解决及说明:

<IfModule mod_proxy.c>
????? ProxyPass /mysys/ http://192.168.8.11:81/mysys/
????? ProxyPassReverse /mysys/ http://192.168.8.11:81/mysys/
</IfModule>


①? 这里有两个mysys,我们分别叫做叫做path_wapm和path_iis

ProxyPass /path_wapm/
???? http://192.168.8.11:81/path_iis/
???? path_wapm:这个是虚拟的目录名称,可以任意指定一个

②ProxyPassReverse /path_wapm/
???? http://192.168.8.11:81/path_iis/
???? path_iis:这个必须通过81端口可以访问的


那么,访问http://wapm服务器/path_wapm的时候,实际访问的将自动转换为了
http://192.168.8.11:81/path_iis/的.

?

③path_wapm如果不加,就不知道访问哪一个虚拟目录的时候需要使用ASP,

path_iis不加,那么就是访问http://192.168.8.11:81/的效果了

简单来说:就是把IIS站点的一个目录,当作WAPM的一个虚拟目录来访问,
可以是IIS站点的一个子目录,也可以是根目录.
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
(四).如果还有不明白的地方,请到
http://w.yi.org/ftp/FAPM/apache/Apache2/zh/mod/mod_proxy.html#<proxy>查对!