• 请不要在回答技术问题时复制粘贴 AI 生成的内容
lancn
V2EX  ›  程序员

PAC 代理配置问题

  •  
  •   lancn · Jul 27, 2017 · 4673 views
  •   You need to sign in to view this topic
    This topic created in 3408 days ago, the information mentioned may be changed or developed.

    是这样的 我的网站最近部分移动用户反映打不开,想通过代理的方式实现移动宽带用户访问 PAC 可单独控制代理规则,想做一个 PAC 文件,用户访问 aaa.cn 走代理,其余正常

    function FindProxyForURL(url, host) {

    if (shExpMatch(url, ".aaa.cn/")) { return "SOCKS5 59.110.224.187:1080"; } if (shExpMatch(url, ".bbb.cn/")) { return "SOCKS5 59.110.224.187:1080"; } if (shExpMatch(url, ".ip138.com/")) { return "SOCKS5 59.110.224.187:1080"; } if (shExpMatch(url, ".ip.cn/")) { return "SOCKS5 59.110.224.187:1080"; }

    }

    pac 代理配置如上,但是网站域名 aaa.cn (无 www )怎么也不生效,只有 www 的生效的,是我配置的设置有误嘛,之前尝试过各种 url ( aaa.cn *.aaa.cn http://aaa.cn http://aaa.cn/*)

    求解~

    4 replies  •  2017-07-28 11:59:45 +08:00
    ajan
    ajan
    Jul 27, 2017❤️1
    1
    去掉 shExpMatch 判断方法!

    这里面是 js 脚本,随便写写
    lancn
    lancn
    OP
    Jul 27, 2017
    2
    JS 不是太懂,去掉判断的话就不可以区分域名代理了 /哭
    flynaj
    flynaj
    Jul 27, 2017❤️1
    3
    var domains = { //google
    "googleusercontent.com": 1,
    "google.com": 1,
    "gstatic.com": 1,
    "youtube.com": 1,
    "ytimg.com": 1,
    "ggpht.com": 1,
    "googlevideo.com": 1,
    "chromium.org": 1,
    "appspot.com": 1,
    "golang.org": 1,
    "googleapis.com": 1,
    "chrome.com": 1,
    "google.tk": 1,
    "android.com": 1,
    "goo.gl": 1

    };

    var proxy = "proxy 127.0.0.1:8080;";

    var direct = 'DIRECT;';


    var hasOwnProperty = Object.hasOwnProperty;

    function FindProxyForURL(url, host) {
    var suffix;
    var pos = host.lastIndexOf('.');
    pos = host.lastIndexOf('.', pos - 1);
    while(1) {
    if (pos == -1) {
    if (hasOwnProperty.call(domains, host)) {
    return proxy;
    } else {
    return direct;
    }
    }
    suffix = host.substring(pos + 1);
    if (hasOwnProperty.call(domains, suffix)) {
    return proxy;
    }
    pos = host.lastIndexOf('.', pos - 1);
    }
    }
    stevegy
    stevegy
    Jul 28, 2017❤️1
    4
    我这里用了 host 参数,没使用 url。名单的话,维护那个数组就可以了。shExpMatch 是正则表达式,注意这里那些星号。我只是比较偷懒。。。


    function FindProxyForURL(url, host)
    {
    var proxy_yes = "SOCKS5 59.110.224.187:1080";

    var proxy_no = "DIRECT";

    var l = [
    "*google*",
    "*goo.gl*",
    "*gmail*",
    "*youtube*",
    "*ytimg.com*",
    "*chrome.com*",
    "*android.com*",
    "*ggpht.com*",
    "*blogger.com*",
    "*wordpress.com*",
    "*facebook.com*",
    "*twitter.com*",
    "*twimg.com*",
    "*tumblr.com*",
    "*instagram.com*",
    "*blogspot.com*",
    "*blogblog.com*",
    "dist.github.com*",
    "*.tensorflow.org*",
    "*shadowsocks.org*",
    ];

    for(var i=0; i<l.length; i++) {
    if ( shExpMatch(host, l[i]) ) return proxy_yes;
    }
    return proxy_no;

    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3699 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 09:49 · PVG 17:49 · LAX 01:49 · JFK 04:49
    ♥ Do have faith in what you're doing.