PAC is a method for conditionally proxying HTTP/HTTPS network requests. Each request is either allowed to continue unproxied to its destination, or is forwarded to a specified proxy server, according to whether specific conditions are met. This is very useful for proxying only specific hosts/domains, or for sending specific requests to specific proxies, etc. If you use proxy tools such as Proxyman or Charles, you may find PAC useful.
In macOS, PAC is configured in macOS System Preferences > Network > Advanced > Proxies > Automatic Proxy Configuration
,
and it can also be configured programmatically using the networksetup
command-line tool.
- MDN — Proxy Auto-Configuration (PAC) file
- Wikipedia — Proxy auto-config
- Apple Support
-
Install Node.js and NPM if you don't already have them installed (you may wish to use NVM to do this).
-
Clone this git repo.
-
Within this repo's root directory, run
npm install
. -
Edit the
www/proxy-auto-config.pac
file to configure your proxying conditions. -
Run
./show-pac-and-start-server.sh
— this will print the contents ofwww/proxy-auto-config.pac
for reference, and then statically serve the PAC file at http://127.0.0.1:5252/proxy-auto-config.pac -
To verify that the PAC file is being correctly served, you can run
./check-pac-server.sh
if you wish. -
The following scripts are available for controlling the macOS PAC from the command-line. Note that you'll probably need to edit these scripts to change the network service name from
'Wi-Fi'
to the name of your network service inmacOS System Preferences > Network
.proxy-control-scripts/proxy-status.sh
proxy-control-scripts/enable-proxy.sh
proxy-control-scripts/disable-proxy.sh
- Remember to run this when you've finished your proxying work!
proxy-control-scripts/reload-proxy.sh
- Useful if you've just edited
www/proxy-auto-config.pac
when the macOS PAC is already enabled.
- Useful if you've just edited
-
You can also view and modify the macOS PAC status in
macOS System Preferences > Network > Advanced > Proxies > Automatic Proxy Configuration
.