上网代理,其实我还是最推荐Squid

2013-08-12 01:24:03 +08:00
 snnn
Squid是一个大名鼎鼎老牌软件,用于做HTTP缓存代理。它非常完善的支持HTTP/1.1 proxy协议,所以我的方法就是:让squid以https的方式提供forward proxy service,然后在客户端使用chrome直接访问。

wget 'http://www.squid-cache.org/Versions/v3/3.3/squid-3.3.8.tar.bz2'
tar -jxvf squid-3.3.8.tar.bz2
cd squid-3.3.8
./configure --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib64 --enable-ssl
--enable-auth-basic=DB --enable-auth-ntlm=none --enable-auth-negotiate=none
--enable-auth-digest=none --disable-auto-locale
--disable-ipv6 --disable-translation --with-logdir=/var/logs
--with-pidfile=/var/run/squid.pid --with-swapdir=/var/spool/squid
--with-default-user=squid --libexecdir=/usr/lib64/squid
make
make install


然后修改Squid的配置文件。先是修改监听的端口号,把http_port变成https_port

https_port 4433 cert=/etc/mycert/server.crt key=/etc/mycert/server.key cafile=/etc/mycert/allca.pem

其中cert和key分别是网站的HTTPS证书和私钥。注意证书的common name一定要和服务器的域名相匹配。cafile是用于签署cert的CA链。

然后配置身份认证。squid默认是按照IP进行权限控制,但是这个对我不适用,因为我是要从公网访问它,client没有一个固定的IP。所以最简单的办法就是通过http basic身份认证。

auth_param basic program /usr/lib64/squid/basic_db_auth
auth_param basic children 5 startup=5 idle=1
auth_param basic realm Squid myRealm
auth_param basic credentialsttl 2 hours
acl pauth proxy_auth REQUIRED
http_access allow pauth
#http_access allow localnet
http_access allow localhost
# And finally deny all other access to this proxy
http_access deny all

如果浏览器不支持Https代理,那么可以通过stunnel转一下

https://www.stunnel.org/

装完stunnel后给它写一个简单的配置文件:

client=yes
fips=no
[proxy]
accept = 127.0.0.1:50000
connect = snnn.xen.prgmr.com:4433
CAfile = /etc/allca.pem

如果是Linux或Mac OS X,把上述内容以文本文件方式保存为/etc/stunnel/stunnel.conf

然后启动 stunnel 程序。直接在命令行上执行 stunnel 回车。

然后测试一下:

curl -L -v —proxy-digest -Usnnn:xxxxx -x http://localhost:50000 http://twitter.com/

其中-U后面是proxy的用户名密码,以冒号分割。
10328 次点击
所在节点    服务器
8 条回复
hcw1588
2013-08-12 08:32:09 +08:00
我是用的squid http+ipv6
snnn
2013-08-12 12:09:45 +08:00
@hcw1588 我觉得ipv6其实没什么用 。 ipv6虽然在美国已经普及,但是服务器都有ipv4公网地址,一般走v4 比走v6 要快。
hcw1588
2013-08-12 12:25:52 +08:00
@snnn 但是仅仅一台国内vps,,我想到的,只有用squid http+ipv6来翻墙。。。
Hyperion
2013-08-12 12:34:45 +08:00
还是推荐shadowsocks,相比之下Squid配置复杂的让人吐血…
snnn
2013-08-12 13:55:17 +08:00
@Hyperion socks协议的特征太明显了,容易被检测出来。 而且对于proxy和cache来说,越接近应用层越有效。shadowsocks没法做cache。
lfcase
2017-02-22 12:10:35 +08:00
我们现在是使用两台 squid (一台内网做透明代理,一台云主机做科学上网),目的是让内网用户上网自动分流,想法是,内网 squid 上设置转发 acl ,符合条件的转抛到云主机的 squid ,相关配置做个简单说明:

云主机 squid ,正常代理,加了一个 ip 来源限制(只有公司出口 IP 才能使用它),这个省略吧

内网 squid ,转发 acl 如下:

cache_peer XX.XX.XX.XX parent 3128 0

acl OutSide url_regex -i "/some/path/to/file" #文件中是一些域名

cache_peer_access XX.XX.XX.XX allow OutSide

never_direct allow OutSide

代理端口如下(内网用户电脑网关指向了它,开启了路由及 iptables 转发):

http_port 3128

http_port 880 intercept

https_port 8443 intercept ssl-bump cert=/etc/squid/ssl/myCA.pem

问题描述:

1 、当取消 iptables 的 443 端口转发,及 https_port 的配置,(个人认为就是 https 代理用 http 的 connect 方法), http 的网站正常,但是 https 的网站无法转抛给云主机的 squid ,(可能是 connect 方法,看不到域名了?)

2 、当开启 443 端口转发及 https_port 的配置,证书总是不信任,总感觉是中间人攻击模式,看 squid 说明( http://wiki.squid-cache.org/Features/SslBumphttp://wiki.squid-cache.org/Features/DynamicSslCerthttp://wiki.squid-cache.org/Features/MimicSslServerCert ),也没有头绪,主要对这块不懂。 希望得到帮助。
snnn
2017-02-22 20:20:55 +08:00
透明 ssl 代理太难搞。除非 client 启用了 sni ,否则就会看不到域名。
你这配置就是用来做中间人的配置啊
lfcase
2017-02-23 14:41:00 +08:00
@snnn 是的,但是工作不正常!

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

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

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

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

© 2021 V2EX