Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux 伺服器

Squid 3.0 反向代理的安裝與 squid.conf 設定要點

Squid 3.0 與 2.X 相比有許多變化,以下把我的設定要點記下來備忘。

安裝

./configure --prefix=/usr/local/squid
make
make install
chown -R nobody.nobody /usr/local/squid/var/
/usr/local/squid/sbin/squid -z

情境設定

假設有兩台 Apache 需要反向代理:www.avnads.cn(x.x.x.x)與 www.britepic.org(y.y.y.y)。若 Apache 與 Squid 同機,要留意埠號衝突:可讓 Apache 改非 80 埠、Squid 佔 80;也可兩者都用 80,但 Apache 只綁回環位址,此時 httpd.conf 寫的是 Listen 127.0.0.1:80。

squid.conf 有四千多行,絕大多數是註解。反向代理大致要動以下幾處。

acl

找到 TAG: acl,在其後加上:

acl sites dstdomain .avnads.cn
acl sites dstdomain .britepic.org

http_access

找到 TAG: http_access,在「# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS」這行下面放自訂規則:

http_access allow sites

位置很關鍵,因為後面還有一段:

# And finally deny all other access to this proxy
http_access deny all

它會拒絕所有未被前面規則放行的流量。

http_port

找到 TAG: http_port,在其後加上:

http_port 80 defaultsite=缺省站點 vhost

一般情況下 vhost 就夠用,但加上 defaultsite 仍有意義——有些 HTTP 1.0 客戶端不送 Host 標頭,有個預設值總比沒有好。

cache_peer

找到 TAG: cache_peer,在其後加上:

cache_peer x.x.x.x parent 80 0 no-query originserver name=foo
cache_peer y.y.y.y parent 80 0 no-query originserver name=bar

cache_peer_domain

找到 TAG: cache_peer_domain,在其後加上:

cache_peer_domain foo www.avnads.cn
cache_peer_domain bar www.britepic.org

cache_peer_access

找到 TAG: cache_peer_access,在其後加上:

cache_peer_access foo allow sites
cache_peer_access bar allow sites

改完存檔,執行 squid -k reconfigure 讓設定生效,再檢視 cache.log 確認沒有解析錯誤。

Copyright © Linux教程網 All Rights Reserved