PAC 代理配置问题

2017-07-27 09:31:14 +08:00
 lancn

是这样的 我的网站最近部分移动用户反映打不开,想通过代理的方式实现移动宽带用户访问 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/*)

求解~

3298 次点击
所在节点    程序员
4 条回复
ajan
2017-07-27 12:35:20 +08:00
去掉 shExpMatch 判断方法!

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

}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/378244

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX