อ้างอิงจาก http://www.thaihosttalk.com/index.php?showtopic=2618
ก่อนอื่นก็ต้องติดตั้ง squid ก่อน ในที่นี้ผมใช้ rpm
ก็เลยพิมพ์ไปว่า
# apt-get install squid
หลังจากติดตั้งเสร็จ ก็มาตั้งค่ามัน แต่ก่อนอื่นต้อง stop ไปก่อน
เผื่อคนแอบใช้ อันที่จริงมันไม่ได้ auto start หรอก ^^'
# service squid stop
# vi /etc/squid/squid.conf
|
http_port 9085 icp_port 0 acl QUERY urlpath_regex cgi-bin ? no_cache deny QUERY cache_mem 1024 MB cache_dir ufs /var/spool/squid 1024 16 256 emulate_httpd_log on redirect_rewrites_host_header off acl all src 0.0.0.0/0.0.0.0 http_access allow all cache_mgr [email protected] cache_effective_user squid cache_effective_group squid httpd_accel_host virtual httpd_accel_port 80 log_icp_queries off cachemgr_passwd changethisforsecurityreason buffered_logs on visible_hostname accelerator.icez.net httpd_accel_with_proxy off httpd_accel_uses_host_header on httpd_accel_single_host off |
จุดที่ต้องดูมี
- http_port 9085 << ตรงนี้จะเป็น port ที่ต้องการให้ squid เปิดรับ connection
- cache_mem 1024 MB << เป็นขนาดพื้นที่ cache ของ squid ครับ
- cache_dir ufs /var/spool/squid 1024 16 256 << อันแรกเป็นที่อยู่ cache ของ squid, อันหลังเป็นขนาดพื้นที่ (รายละเอียด อ่าน config squid เอา)
cache_mgr [email protected] << info เฉยๆ
cachemgr_passwd changethisforsecurityreason << เรื่องการตรวจสอบข้อมูลน่ะครับ ไว้ดูอะไรได้หลายอย่าง เพราะฉะนั้น เปลี่ยนซะ
visible_hostname accelerator.icez.net << ชื่อของ proxy ครับ
นอกนั้นก็ไม่ต้องเปลี่ยนมัน แต่ถ้าอยากทำอะไรกะมันอีกก็ add เพิ่มก็ได้ครับ
หลังจากนั้น ต้องเซตให้ squid auto start แล้วก็ initialize cache ของ squid แล้วก็ start squid
# chkconfig --level 345 squid on
# squid -z
# service squid start
เสร็จแล้วก็มาแก้ firewall กัน ผมใช้ iptables นะครับ
# iptables -t nat -A PREROUTING -p tcp -m tcp -d 192.168.0.1/32 --dport 9085 -j DROP
# iptables -t nat -A PREROUTING -p tcp -m tcp -d 192.168.0.1/32 --dport 80 -j REDIRECT --to-ports 9085
# service iptables save
* แก้ตัวแดงๆ เป็น ip และ port ของ squid นะครับ
อันแรกไว้ block connection เข้า squid โดยตรง
อันหลังไว้ redirect http request เข้า squid ก่อนแล้ว squid จะทำหน้าที่จัดการอีกรอบ
www.hi5agel.com/team