Squid Proxy เป็นเครื่องมือที่ใช้เพื่อการทำ caching file static ต่างๆ ที่ถูกใช้งานใน http ซึ่งนอกเหนือจากการ caching นั้น Squid ยังสามารถทำ ACL (Access Control List) เพื่อป้องกันการใช้งานเว็บไซด์หรือ Port ใดๆที่ไม่อยากให้ user ใช้งานได้อีกด้วย โดยวิธีการติดตั้ง Squid สามารถทำได้โดยทำตามขั้นตอนต่อไปนี้
1. Install required package
1 |
# apt-get install devscripts build-essential fakeroot libssl-dev openssl squid-langpack |
2. Download source code squid
1 |
# apt-get source squid3 |
3. Build Squid Package
1 |
# apt-get build-dep squid3 |
4. เข้าไปเพิ่ม option การ compile ใน debian/rules
1 2 |
# cd squid3-3.5.12 # vim debian/rules |
เพิ่ม –with-openssl และ –enable-ssl-crtd เข้าไปใน option (DEB_CONFIGURE_EXTRA_FLAGS)
5. Build Package
1 |
# dpkg-buildpackage -rfakeroot -b |
6. Install package ที่ถูก build
1 |
# dpkg -i squid-common_3.5.12-1ubuntu7.2_all.deb squidclient_3.5.12-1ubuntu7.2_amd64.deb squid_3.5.12-1ubuntu7.2_amd64.deb |
7. สร้าง ssl db
1 |
# /usr/lib/squid/ssl_crtd -c -s /var/spool/squid/ssldb |
8. Backup Squid Configuration
1 |
# cp /etc/squid/squid.conf /etc/squid/squid.conf.backup |
9. แก้ไข Squid.conf ให้เป็นดังนี้
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl Safe_ports port 70 # gopher acl Safe_ports port 210 # wais acl Safe_ports port 1025-65535 # unregistered ports acl Safe_ports port 280 # http-mgmt acl Safe_ports port 488 # gss-http acl Safe_ports port 591 # filemaker acl Safe_ports port 777 # multiling http acl CONNECT method CONNECT http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access allow all http_port 3128 intercept https_port 3129 intercept ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=4MB cert=/etc/squid/ssl_cert/myca.pem key=/etc/squid/ssl_cert/myca.pem ssl_bump server-first all #always_direct allow all #sslproxy_cert_error deny all #sslproxy_flags DONT_VERIFY_PEER sslcrtd_program /usr/lib/squid/ssl_crtd -s /var/spool/squid/ssl_db -M 4MB sslcrtd_children 8 startup=1 idle=1 coredump_dir /var/spool/squid # Add any of your own refresh_pattern entries above these. refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 refresh_pattern . 0 20% 4320 shutdown_lifetime 2 second |
9. สร้าง ssl cert
1 2 3 4 |
# mkdir /etc/squid/ssl_cert # chown -R squid.squid /etc/squid/ssl_cert # cd /etc/squid/ssl_cert # openssl req -new -newkey rsa:1024 -days 1365 -nodes -x509 -keyout myca.pem -out myca.pem |
10. Restart Squid
1 |
# /etc/init.d/squid restart |
11. Enable IP_Forward
1 |
sysctl net.ipv4.ip_forward=1 |
(หากต้องการเปลี่ยนถาวรให้เข้าไปแก้ไขในไฟล์ /etc/sysctl.conf)
12. สร้าง iptables เพื่อ redirect traffic เข้า Squid
1 2 |
# iptables -A PREROUTING -i eth0 -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 3129 # iptables -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128 |
13. Set ให้ Client วิ่งผ่าน Squid โดยการ setup Proxy ใน Browser หรือการ set ให้เครื่องของ Proxy เป็น Gateway จากนั้นทดสอบใช้งานได้เลย