1. Tập tin squid.conf:
Sao chép nội dung bên dưới vào /etc/squid/squid.conf
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
no_cache deny QUERY
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl all src 0.0.0.0/0.0.0.0
acl mynetwork src 192.168.1.0/255.255.255.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow mynetwork
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow all
httpd_accel_host virtual
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
coredump_dir /var/spool/squid
Bạn phải đổi hàng acl mynetwork src 192.168.1.0/255.255.255.0 với địa chỉ mạng nội bộ bạn muốn.
2. Chỉnh tường lửa:
a. Nếu bạn dùng Linux làm gateway và vnls là một máy riêng trong mạng đang chạy Squid:
Trên máy Linux gateway, gõ:
iptables -t nat -A PREROUTING -i eth0 -s ! địa_chỉ_máy_vnls -p tcp --dport 80 -j DNAT --to địa_chỉ_máy_vnlamp:3128
iptables -t nat -A POSTROUTING -o eth0 -s địa_chỉ_mạng_nội_bộ -d địa_chỉ_máy_vnls -j SNAT --to địa_chỉ_tường_lửa
iptables -A FORWARD -s địa_chỉ_mạng_nội_bộ -d địa_chỉ_máy_vnlamp -i eth0 -o eth0 -p tcp --dport 3128 -j ACCEPT
eth0 là thiết bị mạng nội bộ.
b. Nếu bạn dùng vnls làm gateway và chạy Squid trên cùng một máy:
Trên máy vnlamp, gõ:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
eth0 là thiết bị mạng nội bộ
Reference:
http://www.tldp.org/HOWTO/TransparentProxy.html