看板 Web_Design 關於我們 聯絡資訊
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html 其實與其說是介紹,倒不如說是翻譯, 讀文件是件痛苦,但卻很有用的事情。 我閱讀這分文件的目標在於 希望將 tomcat/ apache /iis /webbbs 等不同port不同平台的服務, 統統整合到 80 port 上得apache , 並透過它的 proxy 來瀏覽其他port的服務. 舉個例子 http://bbs.tonyq.org http://cat.tonyq.org/wiki/ http://tonyq.org/ 依序就是itoc webbbs / tomcat / apache 的服務, 但都是透過apache virtual host轉址 , sub domain交給dns代管不在話下 , 因為在網路上爬蠻久一直沒有完全符合我的需求的文章 , 摘文件閱讀與操作的心得 , 介紹兩種代理器以及能解決我問題的操作方案 , 我英文也很破 , 如果有翻譯方面的問題還請不吝指教. XD ──────────────────────────────── Forward and Reverse Proxies 導向 以及 反向 代理器們 Apache can be configured in both a forward and reverse proxy mode. apache 可以設定 forward、reverse 代理模式. ──────────────────────────────── An ordinary forward proxy is an intermediate server that sits between the client and the origin server. In order to get content from the origin server, the client sends a request to the proxy naming the origin server as the target and the proxy then requests the content from the origin server and returns it to the client. The client must be specially configured to use the forward proxy to access other sites. 一般的forward proxy 是一個介於使用者(指browser)與目標server的中間人。 為了要從server取得資料,使用者把代理者當作目標送一個請求(request), 代理者再轉而對 真‧server 發送請求取回資料給使用者。 使用者必須只透過這個forward proxy 去存取(或說瀏覽)其他網站。 A typical usage of a forward proxy is to provide Internet access to internal clients that are otherwise restricted by a firewall. The forward proxy can also use caching (as provided by mod_cache) to reduce network usage. forward proxy 的典型使用情境為 forward 提供防火牆內的內部使用者們存取網路, 另外 forward proxy 也可以使用mod_cache 提供的快取機制來減少網路傳輸。 The forward proxy is activated using the ProxyRequests directive. Because forward proxys allow clients to access arbitrary sites through your server and to hide their true origin, it is essential that you secure your server so that only authorized clients can access the proxy before activating a forward proxy. forward proxy 可活躍地使用 ProxyRequests 指令,因為 forward proxys 允許 使用者從你的伺服器存取各式各樣的網站,並隱藏他們真正的來源。 因此你必需要保護你的server給只有認證過的使用者來存取這個proxy. Tonyq補註: 各大學宿舍通常都禁止使用者直接存取網站,限制要透過網頁代理伺服器, 這裡說得foward proxy指的就是網頁代理伺服器。 ──────────────────────────────── A reverse proxy, by contrast, appears to the client just like an ordinary web server. No special configuration on the client is necessary. The client makes ordinary requests for content in the name-space of the reverse proxy. The reverse proxy then decides where to send those requests, and returns the content as if it was itself the origin. 與 forward proxy形成對比的 reverse proxy , 它的使用者就像瀏覽普通的web server, 沒有任何特別需要的設定. 使用者對 reverse proxy 發出請求(request)來取得資料 , 由reverse proxy 來決定他要對哪裡送出資料並回傳對應的伺服器內容。 *這裡name-space , 雖然說是知道觀念 , 不過不知道該怎麼翻出來比較通順, 講命名空間整個怪 , 所以略去不翻. :p A typical usage of a reverse proxy is to provide Internet users access to a server that is behind a firewall. Reverse proxies can also be used to balance load among several back-end servers, or to provide caching for a slower back-end server. In addition, reverse proxies can be used simply to bring several servers into the same URL space. reverse proxy 的典型使用情境 , 是提供使用者存取在防火牆後的web server. 它也可以被被用在平衡多個後端伺服器的負擔 , 或者提供緩慢 server 的快取機制。 另外 , reverse proxies 可以簡單的把數個server 整合進同樣的 url 空間*. *此處說得應該是same domain name . A reverse proxy is activated using the ProxyPass directive or the [P] flag to the RewriteRule directive. It is not necessary to turn ProxyRequests on in order to configure a reverse proxy. reverse proxy 可以活躍地使用 ProxyPass 指令 , 或者透過RewriteRule指令, 設定reverse proxy時 , 不需要把 ProxyRequests 設定為 on . *proxy requests on 表示對目標頁面的 request , 全部是透過 apache來進行 , 所以設定時要小心別被拿去當跳板做壞事. ──────────────────────────────── 文件翻完了,最後是配置方法。 在原本apache 的virtauls host設定之外 , 我是這樣設定的 , 紅字的地方是目標的 sub domain , 黃字的地方是目標的web server . (其實不一定要跟目錄, 也可以設定為 /bbs 等等的資料夾路徑.) 有設定servername 時 , 它會針對連上來的domain去處理 , servername一樣時才會做 proxy , 所以雖然 cat.tonyq.org / bbs.tonq.org /tonyq.org 實際上是同一台機器 , 但是連線時會有不同的顯示內容. <VirtualHost *:80> ServerName bbs.tonyq.org ProxyRequests off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://tonyq.org:1223/ ProxyPassReverse / http://tonyq.org:1223/ </VirtualHost> <VirtualHost *:80> ServerName cat.tonyq.org ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://tonyq.org:8180/ ProxyPassReverse / http://tonyq.org:8180/ </VirtualHost> ──────────────────────────────── 參考資料 http://blog.roga.tw/2006/10/08/325/ http://www.debian-administration.org/articles/411 http://www.debian.org.hk/apache-2-2-mod-proxy-ajp-tomcat-5-5 http://0rz.tw/5452I -- What do you want to have ? / What do you have? 從書本中,你可以發現我的各種興趣。 從CD中,你可以瞭解我所喜歡的偶像明星。 或許從文字你很難以瞭解一個人,但從物品可以。 My PPolis , My past. http://ppolis.tw/user/Tony -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 221.169.78.140 ※ 編輯: TonyQ 來自: 221.169.78.140 (11/15 20:01)
weiyucsie:foward -> forward 11/15 20:03
手誤 , 感謝提醒 o(_ _)o ※ 編輯: TonyQ 來自: 221.169.78.140 (11/15 20:05)
bigair:我推~ 剛好最近在碰 11/16 22:47