Skip to content. | Skip to navigation

Personal tools
Log in
Sections
You are here: Home How To OS X Admin Squid Anonymous Proxy on OS X

Squid Anonymous Proxy on OS X

I'll piece together various instructions to set up an anonymous squid proxy on OS X.

 

Overview

These instructions are to setup a remote squid proxy that permits proxy for authenticated users. This purpose is slightly different from setting up a proxy that permits specific machines with specific IP addresses.

Also, I wrote these instructions while setting up Squid Cache version 3.1.16. Details for other squid versions may vary, but the ideas should be similar. For other versions, try these instructions first and troubleshoot from there.

 

Build Squid

If you use authentication with squid (instead of relying on IP based ACLs), it is not sufficient to use fink to install squid because you need to build the authentication helper too. So you will need to build squid yourself. This is fairly easy for you but takes a few minutes for your computer. To build squid, you need XCode installed. It's either free or available at the App Store for $4 or $5.

  1. Download the squid source from http://www.squid-cache.org.
  2. Configure and make the squid build, enabling authentication with the ncsa_auth helper.
  3. ./configure --enable-auth=basic --enable-basic-auth-helpers=NCSA
    make
    sudo make install

This will put squid into /usr/local/squid. Squid is self-contained within this folder, so all configuration will be done there.

 

Setup the Effective Squid User

By default the squid user is nobody. This user already exists on OS X. You only need to change the ownership of one directory:

sudo chown -R nobody:nobody /usr/local/squid/var

 

Configure Squid

These instructions are adapted from http://www.howtoforge.com/anonymous-proxy-using-squid-3-centos-5.x. For details, see this page.

If you have built squid according to these instructions a short squid.conf should have been created in the /usr/local/squid/etc directory. It needs to be replaced with a longer version. Add the following file, named "/usr/local/squid/etc/squid.conf". Its ownership should be root:wheel. Network admins will want to tweak some of these settings, especially some of the ACL. Weekend networking warriors need not care so much, with the one exception of tailoring the dns_nameservers entry if institution specific DNS is desired. Those provided below are google's DNS servers.

#
# Squid Proxy with Authentication
#
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
acl localnet src 172.16.0.0/12    # RFC1918 possible internal network
acl localnet src 192.168.0.0/16    # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

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

#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
# http_access deny all

# Squid normally listens to port 3128
http_port 3128

# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /usr/local/squid/var/cache 100 16 256

# Leave coredumps in the first cache dir
coredump_dir /usr/local/squid/var/cache

# 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

auth_param basic program /usr/local/squid/libexec/ncsa_auth /usr/local/squid/etc/squid_passwd

auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours

#INSERT YOUR OWN RULES(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
acl ncsaauth proxy_auth REQUIRED
http_access allow ncsaauth
# THE DENY ALL CONTROL IS ADDED BACK
http_access deny all

forwarded_for off

acl ip1 myip 10.0.0.1
tcp_outgoing_address 10.0.0.1 ip1

request_header_access Allow allow all
request_header_access Authorization allow all
request_header_access WWW-Authenticate allow all
request_header_access Proxy-Authorization allow all
request_header_access Proxy-Authenticate allow all
request_header_access Cache-Control allow all
request_header_access Content-Encoding allow all
request_header_access Content-Length allow all
request_header_access Content-Type allow all
request_header_access Date allow all
request_header_access Expires allow all
request_header_access Host allow all
request_header_access If-Modified-Since allow all
request_header_access Last-Modified allow all
request_header_access Location allow all
request_header_access Pragma allow all
request_header_access Accept allow all
request_header_access Accept-Charset allow all
request_header_access Accept-Encoding allow all
request_header_access Accept-Language allow all
request_header_access Content-Language allow all
request_header_access Mime-Version allow all
request_header_access Retry-After allow all
request_header_access Title allow all
request_header_access Connection allow all
request_header_access Proxy-Connection allow all
request_header_access User-Agent allow all
request_header_access Cookie allow all
request_header_access All deny all

dns_nameservers 8.8.8.8 8.8.4.4

 

Setup the Authenticated Squid Users

On OS X, htpasswd comes standard at /usr/sbin/htpasswd. Use it to create the passwords for squid.

  1. Create the squid_passwd file.
  2. cd /usr/local/squid/etc/
    sudo touch squid_passwd
  3. Add users like this (this user is called "fordprefect"):
  4. sudo htpasswd squid_passwd fordprefect

 

Setup the Launch Daemon

Put the following file, named "org.squid-cache.squid.plist" into /Library/LaunchDaemons. Its ownership should be root:wheel.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.squid-cache.squid</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/squid/sbin/squid</string>
<string>-N</string>
</array>
<key>TimeOut</key>
<integer>120</integer>
<key>OnDemand</key>
<false/>
</dict>
</plist>

 

Build the Swap Directories

Before you can use squid, you need to build the directories that it uses to cache, etc:

sudo /usr/local/squid/sbin/squid -z

If everything worked fine, the only line of output should end with "Creating Swap Directories".

 

Test the Setup

It is best to test squid from the Terminal to make sure everything is OK.

sudo /usr/local/squid/sbin/squid -NCd1

If you see "Ready to serve requests." near the bottom of the debugging output, then things are working fine. You can stop this instance of squid with Ctrl-C.

 

Using Your Squid

You are now ready to start using squid. You must set up your browser to proxy. I'll give instructions for Firefox as an example.

  1. Under Firefox Preferences, go to the "Advanced" tab then click on "Network" then click "Settings...".
  2. Change the radio button to "Manual proxy configuration".
  3. For "HTTP Proxy:", enter the fully qualified name of your squid server (e.g. "squidserver01.servers.example.org").
  4. For "Port:", enter "3128", which is the default port for squid.
  5. If you have local addresses, like routers, that you need to access without getting routed through the proxy, enter those in "No Proxy for:" (e.g. 192.168.1.1 for dd-wrt).

 

If you have already stopped the test instance (using Ctrl-C), you can start squid without rebooting your machine:

sudo /usr/local/squid/sbin/squid

This instance will stop gracefully when you reboot. After that, squid should start automatically on boot.