### Start Squid using rc.local (BSD-ish systems) Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md This example demonstrates how to add a command to the /etc/rc.local file to start the Squid service on systems that use this method for startup scripts, typically found on BSD-derived operating systems. ```shell if [ -f /usr/local/squid/sbin/squid ]; then echo -n ' Squid' /usr/local/squid/sbin/squid fi ``` -------------------------------- ### Install and Start Squid from Source Source: https://context7.com/squid-cache/squid-cache.github.io/llms.txt This snippet covers compiling and installing Squid from source code, verifying configuration syntax, creating cache directories, starting Squid in foreground for debugging, running as a daemon, checking its status, and testing with squidclient. ```bash # Compile and install Squid from source ./configure --prefix=/usr/local/squid make make install # Verify configuration syntax /usr/local/squid/sbin/squid -k parse # Create cache swap directories (first time only) /usr/local/squid/sbin/squid -z # Start Squid in foreground for debugging /usr/local/squid/sbin/squid -NCd1 # Expected output: "Ready to serve requests." # Start Squid as daemon (production) /usr/local/squid/sbin/squid # Check if Squid is running /usr/local/squid/sbin/squid -k check echo $? # Returns 0 if running # Test with squidclient squidclient http://www.example.com/ > test.html ``` -------------------------------- ### Install Squid from Source Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md After compiling Squid from source, use the 'make install' command to install the proxy server. If ICMP or the pinger is enabled, 'make install-pinger' is also required. Ensure you have the necessary permissions, potentially using 'su'. ```bash % make install % su # make install-pinger ``` -------------------------------- ### Start Squid using init.d script Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md Provides the command to start the Squid service using a standard init.d startup script. This is a common method on many Linux distributions. ```shell /usr/local/squid/sbin/squid ``` -------------------------------- ### Start Squid using inittab Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md This snippet shows how to configure the /etc/inittab file to automatically start and respawn the Squid service. It recommends using a wrapper script 'squid.sh' for more control over the Squid process and logging. ```shell sq:3:respawn:/usr/local/squid/sbin/squid.sh < /dev/null >> /tmp/squid.log 2>&1 ``` -------------------------------- ### Start Squid service with daemontools (symlink) Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md This command shows how to enable the Squid service managed by daemontools by creating a symbolic link in the '/service' directory, which is monitored by 'svscan'. ```shell cd /service ln -s /usr/local/squid/supervise squid ``` -------------------------------- ### Initialize Squid Cache Directories Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md Create the necessary swap directories for Squid by running the Squid executable with the '-z' option. This step is crucial before starting Squid for the first time. Be mindful of permissions if running Squid as root, ensuring log and cache directories are created and owned by the correct user. ```bash % /usr/local/squid/sbin/squid -z ``` -------------------------------- ### Verify Squid Configuration Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md Before starting Squid, verify the syntax and correctness of your configuration file ('squid.conf') using the '-k parse' option. This command checks for syntax errors and fatal misconfigurations. A silent output indicates a valid configuration. ```bash % /usr/local/squid/sbin/squid -k parse ``` -------------------------------- ### Start Squid as a Daemon Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md To run Squid as a background daemon process, simply execute the Squid command without any options. Squid will automatically background itself and spawn a child process to handle requests. Note that if you select an http_port below 1024, you may need to start Squid as root. ```bash % /usr/local/squid/sbin/squid ``` -------------------------------- ### Squid startup script (squid.sh) Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md A sample shell script to manage the Squid startup process. It sets environment variables, navigates to the Squid directory, sets umask, waits for a specific condition, and then executes the Squid binary with '-N' option. It also includes logic to log cache errors. ```shell C=/usr/local/squid PATH=/usr/bin:$C/bin TZ=PST8PDT export PATH TZ # User to notify on restarts notify="root" # Squid command line options opts="" cd $C umask 022 sleep 10 while [ -f /var/run/nosquid ]; do sleep 1 done /usr/bin/tail -20 $C/logs/cache.log \ | Mail -s "Squid restart on `hostname` at `date`" $notify exec bin/squid -N $opts ``` -------------------------------- ### Squid Compilation and Service Setup on Windows with MinGW Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/CompilingSquid.md Steps to compile Squid using the MinGW environment on Windows, including necessary package installations, library preparations, and running Squid as a Windows service. This process involves copying OpenSSL files and renaming libraries. ```bash squid -z squid -N -D -d1 squid -n net start squid ``` -------------------------------- ### Setup oprofile for Squid Profiling Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/KnowledgeBase/LinuxOprofile.md This snippet outlines the initial setup commands for oprofile to prepare it for profiling Squid. It includes shutting down existing oprofile daemons, resetting profiling data, configuring kernel and library separation, and specifying the Squid binary. ```bash opcontrol --shutdown opcontrol --reset opcontrol --vmlinux=/path/to/vmlinux (or --no-vmlinux if you don't have the kernel vmlinux image) opcontrol --separate=lib,thread or maybe (if you want kernel time mixed with the application) opcontrol --separate=lib,thread,kernel opcontrol --image=/path/to/sbin/squid opcontrol --start-daemon ``` -------------------------------- ### Start Squid in Foreground for Debugging Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md To start Squid and monitor its debugging output directly in the terminal, use the '-NCd1' options. This prevents Squid from backgrounding and spawning a child process, allowing you to observe its behavior and confirm it's ready to serve requests. ```bash % /usr/local/squid/sbin/squid -NCd1 ``` -------------------------------- ### Configure Squid Installation Prefix Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/CompilingSquid.md This example shows how to change the default installation directory for Squid using the --prefix option during the configure step. The default location is /usr/local/squid, but this can be modified to a custom path. ```bash % cd squid-x.y.z % ./configure --prefix=/some/other/directory/squid ``` -------------------------------- ### Squid StoreID Helper Input/Output Example Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/Features/StoreID.md Demonstrates the expected input and output format for a Squid StoreID helper program. The helper receives a URL and returns either an error or an OK status with a generated store-id, which Squid uses for caching decisions. ```shell root# /usr/local/squid/bin/new_format.rb ERR http://i2.ytimg.com/vi/95b1zk3qhSM/hqdefault.jpg OK store-id=http://ytimg.squid.internal/vi/95b1zk3qhSM/hqdefault.jpg ``` -------------------------------- ### Squid Compilation Options for OpenSUSE Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/KnowledgeBase/OpenSUSE.md These ./configure options are necessary to install Squid correctly into the OpenSUSE file system structure, addressing differences from default Squid layouts. They specify installation paths for executables, configuration files, state directories, and log files. ```bash --prefix=/usr --sysconfdir=/etc/squid --bindir=/usr/sbin --sbindir=/usr/sbin --localstatedir=/var --libexecdir=/usr/sbin --datadir=/usr/share/squid --sharedstatedir=/var/squid --with-logdir=/var/log/squid --with-swapdir=/var/cache/squid --with-pidfile=/var/run/squid.pid ``` -------------------------------- ### Start and Monitor Squid Service Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/ConfigExamples/Intercept/DebianWithRedirectorAndReporting.md Commands to start the Squid service, monitor access logs in real-time, and parse logs for human-readable output. Requires Squid to be installed and configured. ```bash /etc/init.d/squid3 start ``` ```bash tail -f /var/logs/access.log ``` ```bash tail -f /var/logs/access.log | ccze -C ``` -------------------------------- ### Squid Configuration: Ban URLs with Keywords Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/SquidAcl.md This example demonstrates how to implement a ban list by denying access to URLs containing specific keywords using 'url_regex'. It also shows how to allow access for authenticated clients and finally deny all others. ```squidconf acl Cooking1 url_regex cooking acl Recipe1 url_regex recipe acl myclients src 172.16.5.0/24 http_access deny Cooking1 http_access deny Recipe1 http_access allow myclients http_access deny all ``` -------------------------------- ### Example HTTP Request with Surrogate-Capability Header Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/Features/Surrogate.md An example of an HTTP GET request as seen by a web server, including the Surrogate-Capability header sent by Squid. This header identifies the surrogate proxy. ```http GET / HTTP/1.1 Surrogate-Capability: cdn.example.com="Surrogate/1.0" ... ``` -------------------------------- ### Squid Subdomain ACL Syntax Example Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/SquidAcl.md This example illustrates the syntax for defining domain-based access control lists (ACLs) in Squid, specifically highlighting the difference between exact host matches and entire domain matches. It shows how to use wildcard prefixes (e.g., '*.example.com') for domain matching and notes potential issues with overlapping ACLs. ```squidconf acl FOO dstdomain boulder.co.us vail.co.us .co.us ``` -------------------------------- ### Install Essential Packages with Homebrew on macOS Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/BuildFarm/MacOsInstall.md Installs a comprehensive set of development tools and libraries required for building software like Squid Cache on macOS using Homebrew. This command updates Homebrew, upgrades existing packages, and then installs specific dependencies. ```bash brew update && brew upgrade brew install autoconf automake ccache cppunit gawk gdbm git gnu-sed gnutls grep libtool m4 make nettle openldap openssl ``` -------------------------------- ### Squid IP Cache Manager Output Example Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InnerWorkings.md An example output from Squid's 'ipcache' manager, illustrating DNS lookup caching details. It shows hostnames, flags, reference counts, Time-To-Live (TTL) values in seconds, and the resolved IP addresses. Negative TTL values indicate that the entry has expired and will be refreshed on the next use. ```text Hostname Flags lstref TTL N www.squid-cache.org C 73043 12784 1( 0) 204.144.128.89-OK www.ircache.net C 73812 10891 1( 0) 192.52.106.12-OK polygraph.ircache.net C 241768 -181261 1( 0) 192.52.106.12-OK ``` -------------------------------- ### Squid Configuration: Directory Wildcard Includes Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/Features/ConfigIncludes.md This example shows how to include all configuration files within a specific directory that match a given pattern. This is particularly useful on Unix-based systems for organizing configurations. ```squidconf http_port 3128 include /etc/squid/conf.d/*.conf ... ``` -------------------------------- ### Stop Squid using init.d script Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md Shows the command to gracefully shut down the Squid service using an init.d script. It includes a loop that checks the Squid status and waits for it to stop, with a timeout. ```shell /usr/local/squid/sbin/squid -k shutdown n=120 while /usr/local/squid/sbin/squid -k check && [ $n -gt 0 ]; do sleep 1 echo -n . n=`expr $n - 1` done ``` -------------------------------- ### Squid Configure Options for Windows Service and Hostsfile Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/KnowledgeBase/Windows.md These are valid configure options when compiling Squid on Windows. --enable-win32-service is for creating a Windows service, and --enable-default-hostsfile is for using a default hosts file. ```bash # --enable-win32-service # --enable-default-hostsfile ``` -------------------------------- ### Run Squid Without Backgrounding Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/InstallingSquid.md If you need to run Squid from your terminal without it automatically backgrounding and spawning a child process, use the '-N' command-line option. This is useful for manual control and observation. ```bash /usr/local/squid/sbin/squid -N ``` -------------------------------- ### Cisco Router WCCPv2 Configuration Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/ConfigExamples/SquidAndWccp2.md Configuration for a Cisco 7206VXR router to enable WCCPv2 for web cache redirection. This setup intercepts packets destined for upstream and redirects them to the Squid proxy. ```cisco ip wccp web-cache redirect-list 190 ! interface GigabitEthernet0/1 description web-proxy ip address 10.15.163.10 255.255.255.252 duplex auto speed auto media-type rj45 no negotiation auto ! interface Serial1/0.1 point-to-point ip wccp web-cache redirect out ! interface Serial1/0.2 point-to-point ip wccp web-cache redirect out ! interface Serial1/0.3 point-to-point ip wccp web-cache redirect out ! interface Serial1/0.4 point-to-point ip wccp web-cache redirect out ! interface Serial1/0.5 point-to-point ip wccp web-cache redirect out ! interface Serial1/0.6 point-to-point ip wccp web-cache redirect out ! interface Serial1/0.25 point-to-point ip wccp web-cache redirect out ! access-list 190 permit tcp 10.15.128.0 0.0.63.255 any eq www access-list 190 permit tcp 10.15.128.0 0.0.63.255 any eq 8000 access-list 190 permit tcp 10.15.128.0 0.0.63.255 any eq 8080 ``` -------------------------------- ### Configure Squid with MinGW Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/KnowledgeBase/Windows.md This snippet shows how to configure Squid for compilation using the MinGW environment on Windows. It specifies build information, installation prefix, and disables the default hostsfile. The subsequent 'make' commands are used to build and install the software. ```bash ./configure \ --enable-build-info="Windows (MinGW32)" \ --prefix=c:/squid \ --enable-default-hostsfile=none make check && make install ``` -------------------------------- ### Request Evaluation and Processing in Ruby Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/ConfigExamples/ConfigExamples/StoreIdRubyHelperExample.md Evaluates incoming requests read from standard input. It checks if a request starts with a number followed by a space to determine if it should be concatenated or not. Returns true if concatenated, false otherwise. ```ruby def eval request = gets if (request && (request.match /^[0-9]+ /)) conc(request) return true else noconc(request) return false end end ``` -------------------------------- ### Frontend Load Balancing with 'balance' Software Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/ConfigExamples/ExtremeCarpFrontend.md This example shows how to use the 'balance' software, a GPL-licensed tool, for load balancing traffic to multiple Squid instances. It's particularly useful for older Linux versions lacking advanced iptables features or when failover to a different port is desired if a target becomes unavailable. The command listens on port 3128 and distributes connections to backend servers on localhost ports 3129, 3130, 3131, and 3132. ```bash /PATH/TO/balance 3128 127.0.0.1:3129 127.0.0.1:3130 127.0.0.1:3131 127.0.0.1:3132 ``` -------------------------------- ### Squid Configuration: Allow Specific Clients by IP Source: https://github.com/squid-cache/squid-cache.github.io/blob/main/docs/SquidFaq/SquidAcl.md This example shows how to define an Access Control List (ACL) for a specific range of client IP addresses and then allow access for those clients. It involves defining the ACL with 'acl' and then permitting access with 'http_access allow'. ```squidconf acl myclients src 172.16.5.0/24 http_access allow myclients ```