Apache 取得透過 Reverse Proxy (Varnish) 的 Client 真正 IP (mod_rpaf)

之前介紹 [FreeBSD]high performance caching reverse proxy: Varnish (安裝架設篇) 來當 Web 前端 Reverse Proxy,也有 load balance 的功能,不過碰到這樣的環境,後端 Apache Server 只會抓到 Reverse Proxy IP 來當作 log 紀錄,而無法正確取得 Client 端 IP,Varnish 官網 FAQ 有提到 log 檔案得的解決方法,不過在程式方面,要大量的修改,假設今天 Apache 跑10個 Virtual Host ,不就要去改10個網站程式,背後或許是一些大型 open source 的 Project,改起來相當不容易,也很費工夫。Darkhero 提供了 reverse proxy add forward module for Apache (mod_rpaf) 模組,只要裝上這模組,Apache 就不必動到其它設定就可以正確紀錄 log 檔案,且程式都不必修改,就可以得到正確 IP 了。 FreeBSD Ports 安裝方式: cd /usr/ports/www/mod_rpaf2/ make install clean 修改 httpd.conf (FreeBSD: /usr/local/etc/apache22/httpd.conf) LoadModule rpaf_module libexec/apache22/mod_rpaf. [Read More]

[FreeBSD]high performance caching reverse proxy: Varnish (安裝架設篇)

在上禮拜跟 DarkHero 兄聊到 How To Build a Scalable Web Site (3/6) 的上課講義,互相討論了 MySQL Load balance 以及 http reverse proxy 的方式,以前自己有用 HAProxy 當作 Web 平衡負載,順便紀錄了 HAProxy FreeBSD 安裝方式,這次要來介紹今天重點:Varnish Cache Server,在近幾年流行的 Caching 機制,大家會想到 Squid,只要您設定良好的 Squid 參數,它一定運作的非常穩定,然而它的核心依然是 forward proxy,要架設成 Reverse Proxy 還必需要設定一些參數才可以達到,是有一定的困難性,然而 Varnish Cache Server 底層就是高效能 caching reverse proxy,也因為 Squid 是 1980 年發展出來的,程式架構過於老舊,可以參考 ArchitectNotes 瞭解這部份詳情。也許您會問到 Varnish 可以架設成 forward proxy 嗎?答案是可以的,但是您也許不會這麼做,因為它需要 DNS 技術,以及需要一個非常大且複雜的 Varnish VCL(Varnish Configuration Language) file。 1. 今天要介紹如何在 FreeBSD 系統安裝,在介紹之前,系統必須先安裝好 apache,這樣才可以正確啟動,利用 ports 安裝: [Read More]