日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

同時(shí)具備內(nèi)網(wǎng)代理 利用squid實(shí)現(xiàn)反向代理

我的站點(diǎn)上的所有文件都是靜態(tài)HTML,為了進(jìn)一步的加快網(wǎng)頁(yè)速度,于是使用squid實(shí)現(xiàn)反向代理緩存功能 。
@ 安裝squid
為了偷懶就直接使用ports安裝,因?yàn)槲覍⑺械姆?wù)器系統(tǒng)都安裝在/s分區(qū)中,所以設(shè)置了PREFIX為/s/squid
# cd /usr/ports/www/squid
# setenv PREFIX /s/squid
# make install clean
安裝完成后編輯/s/squid/etc/squid/squid.conf,我的配置內(nèi)容如下:

########## Base control ##########
cache_mgr webmaster
cache_effective_user squid
cache_effective_group squid
visible_hostname sleepcat.3322.org
http_port 127.0.0.1:3128
icp_port 0
cache_dir ufs /usr/cache 300 16 256
cache_access_log /dev/null
cache_log /dev/null
cache_store_log /dev/null
error_Directory /s/squid/etc/squid/errors/Simplify_Chinese
icon_directory /s/squid/etc/squid/icons
mime_table /s/squid/etc/squid/mime.conf
coredump_dir /s/squid/squid/cache
pid_filename /s/squid/squid/logs/squid.pid
hosts_file /etc/hosts
unlinkd_program /s/squid/libexec/squid/unlinkd########## Performance control ##########
cache_mem 8 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 off
log_ip_on_direct on
log_mime_hdrs off
dns_timeout 2 minutes
request_header_max_size 10 KB
request_body_max_size 0 KB
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
negative_ttl 5 minutes
positive_dns_ttl 6 hours
negative_dns_ttl 1 minute
connect_timeout 1 minute
read_timeout 15 minutes
request_timeout 5 minutes
clIEnt_lifetime 1 day
half_closed_clients on
maximum_single_addr_tries 1
uri_whitespace strip
ie_refresh off
########## Access control ############
acl all src 0.0.0.0/0.0.0.0
http_access allow all
http_reply_access allow all
hierarchy_stoplist cgi-bin ?
########## Accelator control ############
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
########## Misc control ###########
ftp_user Squid@
ftp_list_width 32
ftp_passive on
ftp_sanitycheck on


初始化cache
# /s/squid/sbin/squid -z啟動(dòng)squid
# /s/squid/etc/rc.d/squid.sh start@ 設(shè)置apache
因?yàn)橐獙?duì)外部實(shí)現(xiàn)反向透明代理,所以apache不能再在外網(wǎng)IP的80端口服務(wù),我將它設(shè)置到127.0.0.1的80端口,修改httpd.conf中的Listen為:
Listen 127.0.0.1:80
刷新apache配置:
# apachectl restart@ 重定向外網(wǎng)IP的80端口訪問(wèn)
我使用 mpd進(jìn)行PPPoE撥號(hào),所以外網(wǎng)接口為ng0,將所有發(fā)往ng0上的80端口請(qǐng)求轉(zhuǎn)發(fā)到127.0.0.1的3128端口上,即轉(zhuǎn)發(fā)到squid的服務(wù)端口 。轉(zhuǎn)發(fā)規(guī)則如下:
rdr ng0 0.0.0.0/0 port 80 -> 127.0.0.1 port 3128
同時(shí)為了使rdr規(guī)則轉(zhuǎn)換后的包能通過(guò)防火墻,增加如下ipfilter過(guò)濾規(guī)則:
pass in quick on ng0 proto tcp from any to 127.0.0.1 port 3128 keep state@ 設(shè)置/etc/hosts文件
現(xiàn)在我們已經(jīng)實(shí)現(xiàn)下面的功能:
client ------> ng0:80 ------> 127.0.0.1:3128
接下來(lái)就要使squid訪問(wèn)真正的服務(wù)以實(shí)現(xiàn)反向代理緩存 。剛才我已經(jīng)將apache設(shè)置到在127.0.0.1:80端口監(jiān)聽(tīng),現(xiàn)在只要讓squid訪問(wèn)127.0.0.1:80便可,由于我們?cè)趕quid的配置文件中設(shè)置了hosts文件的位置為/etc/hosts,所以我們只要在hosts文件中設(shè)置所有我們的WWW主機(jī)(包括虛擬主機(jī))指向127.0.0.1便可 。
127.0.0.1 matthew.3322.org sleepcat.3322.org mirrors.2288.org
同時(shí)請(qǐng)確保你的主機(jī)搜索順序?yàn)?file bind,如果不是,請(qǐng)執(zhí)行以下命令:
# echo "file" > /etc/host.conf
# echo "bind" >> /etc/host.conf"

推薦閱讀