[1] ProxyPass
是否有想過,讓自己的 Apache Server 可以將幾個不同的目錄分散在不同的 Apache Server 去執行呢?
例如:

當使用者輸入 http://www.diro.tw/gallery 時,實際會連到 http://192.168.0.1
當使用者輸入 http://www.diro.tw/blog 時,實際會連到 http://192.168.0.5/web/blog
而雖然真正執行的是背後這些 192.168.0.x 的機器在跑,使用者卻不會察覺,在網址列上仍然是看到如
http://www.diro.tw/gallery、http://www.diro.tw/blog,這就是 Apache 神奇的 R-Proxy 功能。一般
來說可以用這樣的方式保護後面的 Apache Server,使其不直接曝露在 Internet 下。

[@more@]關於R-Proxy的詳細介紹,已經有許多高手介紹過,在這邊就不再贅述。

至於設定方式,也是相當簡單,只要在 httpd.conf 中設定一行:

ProxyPass /dir http://192.168.0.11/gallery

/gallery 是原本的目錄, http://192.168.0.11/gallery 則是要導向的機器及目錄。

你也可以多設定幾組,例如:

ProxyPass /gallery http://192.168.0.11/gallery

ProxyPass /blog http://192.168.0.5/web/blog

這樣使用者只要輸入 http://diro.tw/blog or http://diro.tw/gallery 就會被導向對應的主機囉!

[2] Named-based VirtualHost + ProxyPass

不過單純只用 ProxyPass 還是不盡理想,因為網址看起來就比較遜了,因此一般建議可以搭配 named-based 的 virtual host

看下面的設定馬上就了解了,以後使用者只要輸入 http://gallery.diro.tw 就可以連到 http://192.168.0.11/gallery 了。

<VirtualHost *:80>

ServerAdmin diro@diro.tw

ServerName gallery.diro.tw

ProxyPass / http://192.168.0.11/gallery/

</VirtualHost>

在使用R-Proxy之前,如果一個 public ip要架好幾台 Apache Server,大多只能採用不同的 port 來達成目標,現在有了

R-Proxy 之後,只要稍加設定,就可以不用再搞一堆 :8080 :8000 之類繁瑣的東西囉。

PS1. R-Proxy 背後不一定要用 private ip,你用 public ip來做也是可以的

PS2. R-Proxy 背後的機器不一定要用 Apache,你要用 IIS 或其它 Web Server 也都是可以的

[參考文件]

1. http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypass

2. http://www.study-area.org/tips/r-proxy_20030117.txt

3. http://fr.linuxfocus.org/English/March2000/article147.shtml

diro 范姜士武 http://diro.tw

diro.fan@gmail.com

Facebook Comments Box