聚沙成塔

養貓的陌生人筆記本

使用反向代理 squid 保護 apache

No Comments »

squid 的功能我就不贅述了,除了當作 httpd-proxy server 之外,還能保護後端的網站,
減少該網站 I/O 的效能消耗。
以下為 squid.conf 的組態設定,#部份是 FreeBSD 的路徑

########## Base control ##########
cache_mgr webmaster
cache_effective_user squid
cache_effective_group squid
visible_hostname cache.arule.net
http_port 80
icp_port 0

#cache_dir ufs /usr/cache 300 16 256
cache_dir ufs /var/spool/squid 300 16 256
#cache_access_log /var/log/squid-cache-access.log
#cache_log /var/log/cache.log
#cache_store_log /var/log/cache_store.log
#error_directory /s/squid/etc/squid/errors/English
error_directory /usr/share/squid/errors/English
#icon_directory /s/squid/etc/squid/icons
icon_directory /usr/share/squid/icons
#mime_table /s/squid/etc/squid/mime.conf
mime_table /etc/squid/mime.conf
#coredump_dir /s/squid/squid/cache
coredump_dir /var/spool/squid
#pid_filename /s/squid/squid/logs/squid.pid
pid_filename /var/run/squid.pid
hosts_file /data/squidhosts
#unlinkd_program /s/squid/libexec/squid/unlinkd
unlinkd_program /usr/lib/squid/unlinkd

########## Performance control ##########

cache_mem 256 MB
cache_swap_low 90
cache_swap_high 95
maximum_object_size 4096 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 8 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
fqdncache_size 1024
cache_replacement_policy lru
memory_replacement_policy lru
emulate_httpd_log on
log_ip_on_direct on
log_mime_hdrs off
dns_timeout 2 minutes
request_header_max_size 10 KB

#不快取動態網頁與禁止快取 https協定
acl QUERY urlpath_regex -i cgi-bin /? /.asp /.php /.jsp /.cgi /.js
no_cache deny QUERY
acl DENYSSL urlpath_regex -i ^https://
cache deny DENYSSL

#支援 http svn 的動作 (LOCK 與 UNLOCK是暫不支援)
extension_methods REPORT MERGE MKACTIVITY CHECKOUT PROPFIND#LOCK UNLOCK

黃字部份比照 /etc/hosts 設定即可,有在此檔案內的 hosts 皆可被反向代理。
更改此檔內容需要重新啟動 squid 才會被重新讀取。

常與 squid 搭配的是 apache mod_mem 模組:

CacheForceCompletion 100
CacheDefaultExpire 3600
CacheMaxExpire 86400
CacheLastModifiedFactor 0.1

CacheEnable disk /
CacheRoot /data/
CacheSize 327680
CacheDirLength 4
CacheDirLevels 5
CacheGcInterval 4

CacheEnable mem /
MCacheSize 8192
MCacheMaxObjectCount 10000
MCacheMinObjectSize 1
MCacheMaxObjectSize 51200

設定好之後,有兩個缺點:

1. apache的access log 全部都 log 到 Linux 的區域網路 ip.
這個目前不知道怎麼解…

2. squid 的模擬 apache log 不完整
這個缺點看網頁上是說可以用 patch 的方式讓 squid 支援 apache combined log.

兩個都麻煩,因此暫時按兵不動….

Leave a Reply