18

I want to apply proxy settings to a particular host only (e.g., www.apple.com) in Mac OS X. How can I do it?

In System Preferences there are only options for bypassing proxy settings for particular hosts.

4 Answers 4

26

You can use the following proxy.pac file to send all traffic to apple.com through the proxy 1.2.3.4 while still going directly to all other hosts:

function FindProxyForURL(url, host) {
    PROXY = "PROXY 1.2.3.4"

    // Apple.com via proxy
    if (shExpMatch(host,"*.apple.com")) {
        return PROXY;
    }
    // Everything else directly!
    return "DIRECT";
}
  1. Save this script as proxy.pac(or any other name you like) on a web server. This can be a local web server (http://localhost/proxy.pac). This is required as of OSX Lion.
  2. Go to the System Preferences.
  3. Select Network.
  4. Select the network you want to change (i.e. "WiFi").
  5. Click Advanced... button.
  6. Click Proxies tab
  7. Check [x] Automatic Proxy-Configuration.
  8. In the URL: field, type in the URL to the file you've created in step 1., for example: http://localhost/proxy.pac. (note: local paths will not work in modern OSX)
  9. Click Save and Apply

Voila! Your own proxy-configuration

For more information on the format of the proxy.pac file have a look at http://en.wikipedia.org/wiki/Proxy_Auto-Config as starting point.

0
13

Actually you can use the file:///path/to/file scheme for the URL, instead of having to rely on a web server.

For example:

file:///Users/youruser/var/proxy/proxy.pac
9
  • 1
    Interestingly this all works for Linux/BSD as well, and possibly even Windows; anywhere Automatic Proxy Configuration is used, this is likely to work.
    – jnbek
    May 2, 2016 at 3:34
  • This should probably be the accepted answer as it avoids overcomplicating the stack in use and as the previous comment mentions - is a far more universal solution.
    – user239546
    Mar 2, 2018 at 16:34
  • If you use file:///...pac, then in some applications you can have issues (e.g. Microsoft apps like Teams and others, see support.microsoft.com/en-us/help/4042151/…), so the best way is to put it on localhost or any public server on the Internet.
    – paly
    Jul 20, 2018 at 10:51
  • 1
    This does NOT work on OSX.
    – jpgeek
    Jun 19, 2019 at 10:34
  • 1
    This does not appear to work on macOS Catalina. I am getting "Unsupported PAC URL scheme - please use HTTP or HTTPS for PAC File URLs" in the system logs.
    – Vaelin
    Mar 22, 2021 at 14:02
3

Adding to @heiglandreas's answer...

@jnbek's solution did not work on Mac OSX for me and I was looking for a simple solution.

So, I created a new folder and copied the pac file into that. Then, I started a simple web server on OSX on port 80 from that folder itself.

Just go into the folder & run this command. Please change the port from 80 to something else if its already occupied.

python -m SimpleHTTPServer 80

Now, I could easily get the proxy.pac file from http://localhost/proxy.pac. Or, for different port use: http://localhost:PORT/proxy.pac.

1

@Rehmat's answer is great, but it's not updated for python 3 and Mac OS X Big Sur:

  1. Create a proxy.pac file in a new directory called proxy-web (in whatever parent directory you want):

    function FindProxyForURL(url, host) {
        PROXY = "PROXY 1.2.3.4"
    
        // Apple.com via proxy
        if (shExpMatch(host,"*.apple.com")) {
            return PROXY;
        }
        // Everything else directly!
        return "DIRECT";
    }
    
  2. Start a web server in that directory where your proxy.pac file is located

    cd proxy-web
    ls
    # proxy.pac
    python -m http.server 80
    
  3. Open Apple -> System Preferences

  4. Click Network

  5. Select the specific network in question (ex: "Thunderbolt Ethernet" or "Wi-Fi")

  6. Click Advanced

  7. Select the Proxies tab

  8. Check the Automatic Proxy Configuration box, input URL: http://localhost/proxy.pac

  9. Click OK and Apply but do not close network settings

  10. Test that it's working by going to apple in CHROME (not SAFARI -- for me, our corporate URLs and proxy did not seem to work in Safari but Chrome worked just fine): apple.com

  11. Test in Safari. If it's not working click "Renew DHCP Lease" under the Advanced → TCP/IP tab back in network settings

  12. Run further tests in your favorite browser by going to non-apple URIs (ex: google.com). If you're proxying a specific subdomain, you'll also want to test other subdomains that are not supposed to be proxied.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .