Guide

squid.conf example for Windows Server, annotated

A complete squid.conf for a Squid proxy on Windows Server that serves your internal network: the listener, access rules for internal subnets, a disk cache, logs, DNS and the Windows paths a Cygwin build of Squid needs. Every line is explained, and the file parses cleanly with squid -k parse.

The complete file

The folders are Squid Proxy Professional's defaults: the program under C:\Program Files\Squid Proxy Professional, and the cache and logs under C:\ProgramData\SquidProxyPro. With another Squid build, change the paths to that build's folders. Replace the example addresses and names with your own.

# ---- Listener -------------------------------------------------------
# Port 3128 on every address of the server. To listen on one address
# only, write: http_port 10.0.0.5:3128
http_port 3128

# The name Squid shows on its error pages. Use the server's DNS name.
visible_hostname proxy.example.local

# ---- Who may use the proxy -----------------------------------------
# Your internal subnets. These are the three private (RFC 1918) ranges;
# list only the ones you use, for example: 10.20.0.0/16
acl localnet src 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16

# Ports clients may reach through the proxy, and the only port they may
# open a tunnel (CONNECT) to.
acl SSL_ports port 443
acl Safe_ports port 80 443 21 1025-65535

# Read top to bottom; the first rule that matches decides.
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny to_localhost
http_access deny to_linklocal
http_access allow localhost
http_access allow localnet
http_access deny all

# ---- DNS -----------------------------------------------------------
# A Cygwin Squid cannot read Windows' DNS settings. Name your DNS
# servers (on Active Directory, your domain controllers).
dns_nameservers 10.0.0.10 10.0.0.11

# ---- Files and folders ---------------------------------------------
# Cygwin form (/cygdrive/c/... for C:\...), in quotes, so a path with a
# space stays whole. Quoting is switched on here and off after the block.
configuration_includes_quoted_values on

# Disk cache: ufs store, 1024 MB, 16 x 256 subfolders.
cache_dir ufs "/cygdrive/c/ProgramData/SquidProxyPro/cache" 1024 16 256

# access.log: one line per request. stdio: = Squid writes the file itself.
access_log "stdio:/cygdrive/c/ProgramData/SquidProxyPro/logs/access.log"
# cache.log: Squid's own messages, including why it would not start.
cache_log "/cygdrive/c/ProgramData/SquidProxyPro/logs/cache.log"

# Error pages, icons, MIME table and the cache's file-removal helper,
# from the program folder.
error_directory "/cygdrive/c/Program Files/Squid Proxy Professional/squid/share/errors/templates"
icon_directory "/cygdrive/c/Program Files/Squid Proxy Professional/squid/share/icons"
mime_table "/cygdrive/c/Program Files/Squid Proxy Professional/squid/etc/mime.conf.default"
unlinkd_program "/cygdrive/c/Program Files/Squid Proxy Professional/squid/bin/unlinkd.exe"

# Squid's process ID file, and where it would write a crash dump.
pid_filename "/cygdrive/c/ProgramData/SquidProxyPro/runtime/squid.pid"
coredump_dir "/cygdrive/c/ProgramData/SquidProxyPro/runtime"

# Windows' own hosts file, so its entries apply through the proxy too.
hosts_file "/cygdrive/c/Windows/System32/drivers/etc/hosts"

configuration_includes_quoted_values off

# ---- Memory, logs and stopping -------------------------------------
# Memory for objects in transit and the most used cached objects.
# Squid's total memory use is higher than this.
cache_mem 128 MB

# Old copies kept of each log when it is rotated (.0 is the newest).
logfile_rotate 4

# A Cygwin build cannot look up client MAC addresses; without this
# line Squid logs an error for every connection.
eui_lookup off

refresh_pattern ^ftp:             1440 20% 10080
refresh_pattern -i (/cgi-bin/|\?) 0    0%  0
refresh_pattern .                 0    20% 4320

# Stop within a few seconds when the service stops (default 30).
shutdown_lifetime 3 seconds

Access rules

Squid checks the http_access lines in order and stops at the first one that matches. Put every deny that must always apply before the allow lines, and end with http_access deny all, so a computer you did not list is refused rather than allowed. Without that last line, an open proxy on your network is one mistake away.

  • localnet is the list of networks allowed to use the proxy. Name your own subnets rather than all three private ranges if only some of them should browse through it. Several values on one acl line, or several lines with the same name, add up.
  • Safe_ports and SSL_ports stop the proxy being used to reach mail servers or other services on unusual ports, and stop HTTPS tunnels (CONNECT) to anything but port 443. They follow Squid's own recommended configuration.
  • to_localhost and to_linklocal stop clients reaching services on the proxy server itself through the proxy, and link-local addresses such as cloud metadata services.
  • localhost, to_localhost, to_linklocal, CONNECT and all are built in to current Squid releases. An older release that does not know one reports it when you parse the file.

To block sites for everyone, add a destination rule above allow localnet:

acl blocked_sites dstdomain .example.com .example.net
http_access deny blocked_sites

A leading dot matches the domain and every name under it.

Windows paths in squid.conf

Most Squid builds for Windows are made with Cygwin, and a Cygwin program expects Unix-style paths: C:\ProgramData\SquidProxyPro\cache is written /cygdrive/c/ProgramData/SquidProxyPro/cache, with forward slashes.

Squid also cuts a value at the first space. Unquoted, /cygdrive/c/Program Files/... becomes /cygdrive/c/Program, and Squid exits before it opens its log. Quotes alone do not help: Squid keeps the quote marks as part of the path unless configuration_includes_quoted_values on comes first. The example switches it on just for the block of paths and off again after it, so the rest of the file is read the way Squid normally reads it.

The simplest alternative is a folder with no spaces in its name for everything Squid opens. The example keeps the quoting because the program folder is under C:\Program Files.

A Cygwin build also looks for its error pages, icons, MIME table and helpers under the folder it was compiled for, which does not exist on your server. The error_directory, icon_directory, mime_table and unlinkd_program lines point at the copies that came with the build.

Cache

cache_dir ufs <folder> 1024 16 256 is a disk cache of 1024 MB in 16 folders of 256 subfolders each. Size it to the disk you can spare; the cache folder should be on a local disk.

Use the ufs store. In our testing aufs failed under real load on Cygwin, and diskd needs System V message queues, which Cygwin provides only through its cygserver service.

Squid does not create the cache's folder structure itself. After adding or changing a cache_dir line, stop Squid and run squid -z -f <squid.conf> once.

Logs

access.log has one line for every request: time, client address, result, size, method and address. cache.log holds Squid's own messages, and is the first place to look when Squid will not start. To turn access.log off, write access_log none.

logfile_rotate 4 keeps four old copies when the logs are rotated, but Squid rotates only when told to with squid -k rotate, and on Windows nothing does that by default. Schedule it, for example weekly with Task Scheduler, or the logs grow until the disk is full.

The access log records every address your users visit. Keep the log folder readable by administrators and the service account only.

DNS

A Cygwin Squid takes its DNS servers from /etc/resolv.conf, which Windows does not have. With neither that file nor a dns_nameservers line, Squid logs that it could not find any name servers and every request fails to resolve. The example names two DNS servers. On an Active Directory network use your domain controllers, or whichever servers resolve your internal names, and change the line when they change.

Checking and applying it

Check the file before using it:

squid.exe -k parse -f /cygdrive/c/path/to/squid.conf

Read the output rather than relying on the exit code: look for lines with FATAL, ERROR or WARNING. Then restart the Squid service, or have a running Squid re-read the file with squid.exe -k reconfigure -f <squid.conf>. Open the port in Windows Firewall as shown in the documentation, and test from a client with curl -I -x http://proxy.example.local:3128 https://www.example.com/.

squid.conf in Squid Proxy Professional

In Squid Proxy Professional the management console writes squid.conf for you, at C:\Program Files\Squid Proxy Professional\squid\etc\squid.conf, with the same folders and the same quoting as the example. Do not replace it with a hand-written file.

  • The file has two sections. The managed section is written from the Setup Wizard, the Configuration page and the Access Rules page, and rewritten on every save. The User custom section after it is yours, and is kept as it is across saves.
  • Every save is checked with squid -k parse first, and the previous file is kept in C:\ProgramData\SquidProxyPro\config\squid.conf.backups\.
  • Make access rules on the Access Rules page. The custom section comes after the final http_access deny all, so an http_access line there is never reached.
  • There is no dns_nameservers line: the service writes Squid's resolv.conf from the server's Windows DNS settings at every start and when they change. A dns_nameservers line in the custom section takes over from that.
  • The service rotates the logs on the schedule chosen next to the log switches, so no scheduled task is needed.

See the documentation for first-time setup, and the Windows service guide for how the service runs Squid.

Try it

Let the console write squid.conf.

The 30-day evaluation is the full product, and starts on activation.