2013年10月3日 星期四

利用 IIS7 的 ARR 模組做到 Reverse Proxy 機制

為了讓 IIS 達到類似Apache Proxy 功能,
所以找到了使用 ARR (Application Request Routing) 這個模組
目前的最新版本是 3.0
我的ARR是透過下載 Web Platform Installer 4.6 來安裝

1.安裝 ARR 3.0 & URL Rewrite

2. 在IIS 操作介面中使用 URL Rewrite
3.Add Rule(s)

4. Specify Rewrite Map
5.Add Mapping Entry
6. 回到URL Rewrite 介面去編輯剛剛新增的 Rule & 先設定 Match URL
   這裡的Pattern經過我實驗的結果是針對path及之後的Query
   Action 要使用的時候使用 {R:0}
7. 設定條件( Conditions )

這裡設定的就是將HTTP_HOST 經過剛剛設定的 ReverseProxy 給替換成新的
取用的時候使用{C:0}
8.設定Action
記得 Append query string 與 Stop processing of subsequent rules 要打勾

9. 進入Application Request Routing 進行設定, 啟用Proxy功能, 以及取消勾選 Reverse rewrite host in response headers選項

參考網址:
http://blog.miniasp.com/post/2009/04/13/Using-ARR-to-implement-Reverse-Proxy.aspx
http://blog.miniasp.com/post/2010/11/25/Setting-the-right-REMOTE_ADDR-behind-the-Reverse-Proxy-using-IIS-URL-Rewrite-Module.aspx
http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-rule-template
http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/