V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lancn
V2EX  ›  程序员

PAC 代理配置问题

  •  
  •   lancn · 2017-07-27 09:31:14 +08:00 · 3259 次点击
    这是一个创建于 2437 天前的主题,其中的信息可能已经有所发展或是发生改变。

    是这样的 我的网站最近部分移动用户反映打不开,想通过代理的方式实现移动宽带用户访问 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 条回复    2017-07-28 11:59:45 +08:00
    ajan
        1
    ajan  
       2017-07-27 12:35:20 +08:00   ❤️ 1
    去掉 shExpMatch 判断方法!

    这里面是 js 脚本,随便写写
    lancn
        2
    lancn  
    OP
       2017-07-27 14:06:06 +08:00
    JS 不是太懂,去掉判断的话就不可以区分域名代理了 /哭
    flynaj
        3
    flynaj  
       2017-07-27 20:36:25 +08:00   ❤️ 1
    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
        4
    stevegy  
       2017-07-28 11:59:45 +08:00   ❤️ 1
    我这里用了 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;

    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2693 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 15:10 · PVG 23:10 · LAX 08:10 · JFK 11:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.