| « NAS: Display Squid cachemgr | The Friday Picture: Craftmanship » |
There you are, with that 1TB NAS and you surf mostly the same websites and in the process waste plenty of time waiting on downloads. So why not install your own Squid-proxy server on your NAS?
With the Synology and the pre-requisite of having ipkg installed - this takes no more than 10 minutes.
Update (2008-12-22): I have adjusted the Squid-configuration to block websites for unlisted IP-addresses. If you don't require this (and want your kids to download several gigs of You Tube-videos) then delete the lines acl nonblockedip, acl blocksites and http_access deny blocksites.
In my example, my NAS IP is 172.16.0.97 and my IP range on my LAN is 172.16.0.0 - adjust this accordingly below:
- Install squid: ipkg install squid
Adjust Squid's config-file located in /opt/etc/squid/squid.conf:
Code:
## SQUID CONFIGcache_mgr Gerd@Naschenweng.info## Those are the ports the proxy is going to listen tohttp_port 172.16.0.97:3128http_port 172.16.0.97:8080# TAG: visible_hostname# The host-name of the proxy-server. Can really be anythingvisible_hostname MuffinStationProxy# DISK CACHE OPTIONS# -----------------------------------------------------------------------------# Disk-cache options. Just adjust the cache-siz (in my case 20GB)cache_replacement_policy lrucache_dir ufs /opt/var/squid/cache/ 20000 16 256minimum_object_size 0 KBmaximum_object_size 2097152 KBmaximum_object_size_in_memory 1024 KB# MEMORY CACHE OPTIONS# -----------------------------------------------------------------------------# TAG: cache_mem (bytes)cache_mem 8 MBmemory_replacement_policy lru# ACCESS CONTROLS# -----------------------------------------------------------------------------acl all src 0.0.0.0/0.0.0.0acl manager proto cache_objectacl localhost src 127.0.0.1/255.255.255.255acl our_networks src 172.16.0.0/24 172.16.1.0/24acl to_localhost dst 127.0.0.0/8acl nonblockedip src 172.16.0.3 172.16.0.5# childblocksacl blocksites dstdomain "/opt/etc/squid/restricted-sites.squid"#Block childblocked siteshttp_access deny blocksites !nonblockedip allhttp_access allow manager localhosthttp_access allow manager our_networkshttp_access deny manager# Allow all clients from my networkhttp_access allow our_networks# And finally deny all other access to this proxyhttp_access deny all#Allow ICP queries from everyoneicp_access allow all# LOG-FILES# -----------------------------------------------------------------------------access_log /opt/var/squid/logs/access.log squid#cache_log none#cache_log /opt/var/squid/logs/cache.log#cache_access_log none#cache_access_log /opt/var/squid/logs/access.log#cache_store_log none#cache_store_log /opt/var/squid/logs/store.log# OPTIONS FOR TUNING THE CACHE# -----------------------------------------------------------------------------# TAG: cache# A list of ACL elements which, if matched, cause the request to# not be satisfied from the cache and the reply to not be cached.# In other words, use this to force certain objects to never be cached.## You must use the word 'DENY' to indicate the ACL names which should# NOT be cached.## Default is to allow all to be cached#We recommend you to use the following two lines.acl QUERY urlpath_regex cgi-bin \?cache deny QUERYrefresh_pattern ^ftp: 1440 20% 10080refresh_pattern ^gopher: 1440 0% 1440refresh_pattern . 0 20% 4320refresh_pattern \.gif 1440 50% 40320 reload-into-imsrefresh_pattern \.jpg 1440 50% 40320 reload-into-imsrefresh_pattern \.tif 4320 50% 43200refresh_pattern \.png 1440 50% 40320 reload-into-imsrefresh_pattern \.jpeg 1440 50% 40320 reload-into-imsrefresh_pattern ^http://*.google.*/.* 720 100% 4320# refresh patterns to enable caching of MS windows updaterefresh_pattern windowsupdate\.microsoft\.com/.*\.(cab|exe|psf) 4320 100% 120960 reload-into-imsrefresh_pattern update\.microsoft\.com/.*\.(cab|exe|psf) 4320 100% 120960 reload-into-imsrefresh_pattern office\.microsoft\.com/.*\.(cab|exe|psf) 4320 100% 120960refresh_pattern windowsupdate\.com/.*\.(cab|exe|psf) 4320 100% 120960 reload-into-imsrefresh_pattern download\.microsoft\.com/.*\.(cab|exe|psf) 4320 100% 120960 reload-into-imsrefresh_pattern microsoft\.com 4320 100% 10080pipeline_prefetch on# Apache mod_gzip and mod_deflate known to be broken so don't trust# Apache to signal ETag correctly on such responsesacl apache rep_header Server ^Apachebroken_vary_encoding allow apache# Leave coredumps in the first cache dircoredump_dir /opt/var/squid/cache# Disable cachemgr passwordcachemgr_passwd none all- Take note from my above config, that I chose a cache-size of 20(!) GB (cache_dir).
- Validate your Squid configuration with squid -k parse
- Create the Squid cache-directories with squid -z
- Start Squid manually to check for errors: squid -NCd1
- Create a symbolic link so that Squid starts automatically: ln -s /opt/etc/init.d/S80squid /usr/syno/etc/rc.d/
- Once you restart the NAS, Squid should be started automatically (log files are in /opt/var/squid/logs)
Dummy error: Happened to me - if Squid starts and you don't notice any improvements in browsing speed, make sure that you have your browser's proxy settings adjusted ![]()
IMPORTANT: As I have the caching server within a DMZ/Firewall, security-concerns are secondary. All users having access to the LAN and fall within the IP-range will automatically have access to the caching-proxy. The implementation of Squid was for improving the browsing/web-experience (speed has improved by almost 200% and average bandwidth consumption dropped by 30%).
Follow up:
If you get everything running, you should familiarise yourself with the statuses in Squid's access-log:
- TCP_HIT: A valid copy of the requested object was in the cache.
- TCP_MEM_HIT: A valid copy of the requested object was in the cache, AND it was in memory so it did not have to be read from disk.
- TCP_NEGATIVE_HIT: The request was for a negatively-cached object. Negative-caching refers to caching certain types of errors, such as "404 Not Found." The amount of time these errors are cached is controlled with the negative_ttl configuration parameter.
- TCP_MISS: The requested object was not in the cache.
- TCP_REFRESH_HIT: The object was in the cache, but STALE. An If-Modified-Since request was made and a "304 Not Modified" reply was received.
- TCP_REF_FAIL_HIT: The object was in the cache, but STALE. The request to validate the object failed, so the old (stale) object was returned.
- TCP_REFRESH_MISS: The object was in the cache, but STALE. An If-Modified-Since request was made and the reply contained new content.
- TCP_CLIENT_REFRESH: The client issued a request with the "no-cache" pragma.
- TCP_IMS_HIT: The client issued an If-Modified-Since request and the object was in thecache and still fresh.

squid -k parse
2008/12/11 03:36:00| WARNING: '0.0.0.0/0.0.0.0' is a subnetwork of '0.0.0.0/0.0.0.0'
2008/12/11 03:36:00| WARNING: because of this '0.0.0.0/0.0.0.0' is ignored to keep splay tree searching predictable
2008/12/11 03:36:00| WARNING: You should probably remove '0.0.0.0/0.0.0.0' from the ACL named 'all'
2008/12/11 03:36:00| WARNING: '127.0.0.1' is a subnetwork of '127.0.0.1'
2008/12/11 03:36:00| WARNING: because of this '127.0.0.1' is ignored to keep splay tree searching predictable
2008/12/11 03:36:00| WARNING: You should probably remove '127.0.0.1' from the ACL named 'localhost'
2008/12/11 03:36:00| WARNING: '127.0.0.0/255.0.0.0' is a subnetwork of '127.0.0.0/255.0.0.0'
2008/12/11 03:36:00| WARNING: because of this '127.0.0.0/255.0.0.0' is ignored to keep splay tree searching predictable
2008/12/11 03:36:00| WARNING: You should probably remove '127.0.0.0/255.0.0.0' from the ACL named 'to_localhost'
PLease helpme
Cheers
P
acl myschool src [wanip]/32
http_access allow myschool
Is this secure...?
Additionally i added AddZap (http://librenix.com/?inode=4483).
On my DS 207.128 : PERFECT.
FATAL: comm_select_init: epoll_create(): (38) Function not implemented
I thought the latest optware version had been compiled w/o epoll
I want to create a transparent proxy with squid and netgear router.
Tried some configuration but nothing works !
Any ideas ?
Thankyou
Regards