1.ทำความเข้าใจกับคำว่า " refresh_pattern "
2.แก้ไขไฟล์ คอนฟิก squid.conf.tmpl
3.รีสตาร์ทเซอร์วิส ของ Squid
1.ทำความเข้าใจกับคำว่า " refresh_pattern "


refresh pattern ใน squid.conf จะอยู่ในรูปแบบ:
refresh_pattern [-i] regex min percent max [options]
โดยที่




ตัวอย่างเช่น
refresh_pattern -i \.gif$ 1440 20% 10080
หมายความว่า: ถ้าอ็อบเจกต์ *.gif มี header ระบุเวลาหมดอายุ ก็เชื่อถือตาม header นั้น จบ ถ้าไม่มี จึงพิจารณาต่อไป ถ้าอ็อบเจกต์อยู่ในแคชต่ำกว่า 1440 นาที (1 วัน) ถือว่ายังใหม่อยู่ ใช้ค่าในแคชตอบกลับได้ทันที
ถ้าอ็อบเจกต์อยู่ในแคชมานานเกิน 10080 นาที (7 วัน) ถือว่าเก่าแล้ว ให้ดึงอ็อบเจกต์มาใหม่จากเว็บเซิร์ฟเวอร์
ถ้า อายุในแคชของอ็อบเจกต์อยู่ระหว่าง 1440-10080 นาที ให้พิจารณาอายุในแคช ว่าถึง 20% ของอายุจริงหรือไม่ เช่น ถ้าเว็บเซิร์ฟเวอร์รายงานมาว่าอ็อบเจกต์นี้สร้างขึ้นเมื่อ 10,000 นาทีที่แล้ว ก็พิจารณาว่าอ็อบเจกต์อยู่ในแคชมานานถึง 20% ของ 10,000 คือ 2,000 นาทีหรือไม่ ถ้ายังไม่ถึง ก็ถือว่ายังใหม่ ถ้าถึง ก็ถือว่าเก่าแล้วส่วน options หรือตัวเลือกเพิ่มเติม ส่วนใหญ่จะเป็นการพยายามละเมิดมาตรฐาน HTML เพื่อเพิ่มอัตราการแคช จึงควรระมัดระวังในการใช้งาน ตัวเลือกมีดังนี้:
override-expire -- ไม่ต้องสนใจ header ระบุเวลาหมดอายุที่เว็บเซิร์ฟเวอร์บอกมา (พิจารณาตามกฎเสมอ)
override-lastmod -- ไม่สนใจ header ระบุเวลาเปลี่ยนแปลงล่าสุดที่เว็บเซิร์ฟเวอร์บอกมา (ถือว่าอ็อบเจกต์มีอายุจริงเท่ากับ min แม้จะเพิ่งเปลี่ยนแปลงใหม่)
reload-into-ims -- เปลี่ยน request "no-cache" จากลูกข่ายให้เป็น If-Modified-Since
ignore-reload -- ไม่สนใจ header "no-cache" จากลูกข่าย และจะใช้ข้อมูลในแคชถ้าทำได้
ignore-no-cache -- ไม่สนใจ header "Pragma: no-cache" และ "Cache-control: no-cache" ที่ส่งมาจากเว็บเซิร์ฟเวอร์ ซึ่ง HTTP RFC ไม่ได้อนุญาตให้เว็บเซิร์ฟเวอร์ทำ แต่ก็มักจะทำกัน
ignore-no-store -- ไม่สนใจ header "Cache-control: no-store" ที่ส่งมาจากเว็บเซิร์ฟเวอร์
ignore-private -- ไม่สนใจ header "Cache-control: private" ที่ส่งมาจากเว็บเซิร์ฟเวอร์
ignore-auth -- เก็บอ็อบเจกต์ที่ต้องผ่านการยืนยันตัวบุคคลของผู้อ่านลงแคชด้วย
refresh-ims -- ส่ง request If-Modified-Since ไปที่เว็บเซิร์ฟเวอร์เมื่อผู้ใช้ refresh หน้าเว็บ
คุณ สามารถปรับ refresh pattern ให้เก็บอ็อบเจกต์ที่มักไม่มีการเปลี่ยนแปลง เช่น รูปภาพ เสียง วีดิทัศน์ แฟ้มโปรแกรม แฟ้มบีบอัด ฯลฯ ให้อยู่ในแคชนานขึ้นได้ เพื่อเพิ่มอัตราการ hit เช่น (คัดลอกมาจากบทความต้นตอ):
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i \.(gif|png|jpg|jpeg|ico)$ \
10080 90% 43200 override-expire ignore-no-cache ignore-no-store ignore-private
refresh_pattern -i \.(iso|avi|wav|mp3|mp4|mpeg|swf|flv|x-flv)$ \
43200 90% 432000 override-expire ignore-no-cache ignore-no-store ignore-private
refresh_pattern -i \.(deb|rpm|exe|zip|tar|tgz|ram|rar|bin|ppt|doc|tiff)$ \
10080 90% 43200 override-expire ignore-no-cache ignore-no-store ignore-private
refresh_pattern -i \.index.(html|htm)$ 0 40% 10080
refresh_pattern -i \.(html|htm|css|js)$ 1440 40% 40320
refresh_pattern . 0 40% 40320
กฎ จะถูกนำมาตรวจสอบเรียงทีละกฎจากบนลงล่าง จนกว่าจะพบกฎแรกที่ตรง ก็จะใช้กฎนั้นและหยุดตรวจสอบต่อ ดังนั้น กฎสุดท้ายจึงเป็นกฎที่เอาไว้รองรับแพตเทิร์นที่เหลือโดยทั่วไป และมักจะแยกกฎสำหรับโพรโทคอลอื่นอย่างเช่น FTP และ gopher เอาไว้บนสุด เพื่อกันไม่ให้มาใช้กฎด้านล่าง
2.แก้ไขไฟล์ คอนฟิก squid.conf.tmpl2.1 เปิดโปรแกรม winscp ขึ้นมา แล้วเข้าไปที่ /etc/squid และทำการคลิกขวาที่ไฟล์ชื่อ squid.conf.tmpl แล้วเลือก Edit ดังรูป
2.2 ต่อไปให้นำคำสั่งนี้ ไปเพิ่มที่ส่วนท้ายของไฟล์ squid.conf.tmpl ดังรูป แล้วทำการบันทึก
refresh_pattern -i \.art$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.crw$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.djvu$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.ttf$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.fpx$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.icn$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.ico$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.icl$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.kdc$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mag$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.sif$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.aifc$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.aiff$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.asf$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.au$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.avi$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.m1v$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mid$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.midi$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mp2$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mp2v$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mp3$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mpa$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mpe$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mpeg$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mpg$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mpv2$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.rmi$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.snd$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.wav$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.wma$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.wmv$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.sid$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.pcd$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.pic$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.pict$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.pix$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.pbm$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.pgm$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.ppm$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.eps$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.psp$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.xbm$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.xpm$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.bmp$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.jpeg$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.pcx$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.png$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.tga$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.tiff$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.gif$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.wmf$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.emf$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.pic$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.iff$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.psd$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.ras$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.rs$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.sgi$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.swf$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.pdf$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.exe$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.zip$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.rar$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mov$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.cda$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mp1$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.aac$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.nsa$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.ogg$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.kar$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.miz$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mod$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mdz$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.nst$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.stm$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.stz$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.s3m$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.s3z$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.it$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.itz$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.xm$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.xmz$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.mtm$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.ult$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.669$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.far$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.amf$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.okt$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.ptm$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.voc$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.aif$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.m2v$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.nsv$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.m3u$ 525960 80% 525960 reload-into-ims
refresh_pattern -i \.pls$ 525960 80% 525960 reload-into-ims
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
-----------------------------------------------------------------------------------------------


3.รีสตาร์ทเซอร์วิส ของ Squid
ไม่มีความคิดเห็น:
แสดงความคิดเห็น